package cc.telecomdigital.tdstock.activity.groups.index;

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources.NotFoundException;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Html;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.Animation.AnimationListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import cc.mango.common.FinalKey;
import cc.telecomdigital.tdstock.CommonDefn;
import cc.telecomdigital.tdstock.CustomizeDialog;
import cc.telecomdigital.tdstock.DBHelper;
import cc.telecomdigital.tdstock.DefaultClickHandler;
import cc.telecomdigital.tdstock.ITDLApplication;
import cc.telecomdigital.tdstock.R;
import cc.telecomdigital.tdstock.StringUtils;
import cc.telecomdigital.tdstock.CommonDefn.DataMode;
import cc.telecomdigital.tdstock.CommonDefn.DoThingsReturn;
import cc.telecomdigital.tdstock.Framework.UniqueItem.TDStockLog;
import cc.telecomdigital.tdstock.Framework.UniqueItem.ScreenOrientationChangeListener.IScreenOrientationChangeListener;
import cc.telecomdigital.tdstock.Framework.UniqueItem.ScreenOrientationChangeListener.SCR_ORIENTATION;
import cc.telecomdigital.tdstock.Http.H_CODE;
import cc.telecomdigital.tdstock.Http.Services.HttpAppInfo;
import cc.telecomdigital.tdstock.Http.Services.H_HttpServiceRequest.H_UserClient_HttpRequest_Result;
import cc.telecomdigital.tdstock.Tools.ActivityGroupController;
import cc.telecomdigital.tdstock.activity.BMPBaseActivity;
import cc.telecomdigital.tdstock.activity.chart.IndexChartActivity;
import cc.telecomdigital.tdstock.activity.groups.IndexGroup;
import cc.telecomdigital.tdstock.activity.groups.monitor.util.MonitorUtil;
import cc.telecomdigital.tdstock.activity.groups.monitor.util.SaveBookMarkAsyncTask;
import cc.telecomdigital.tdstock.model.IndexFuturesInfo;
import cc.telecomdigital.tdstock.model.IndexInfo;
import cc.telecomdigital.tdstock.model.WorldFuturesInfo;
import cc.telecomdigital.tdstock.model.WorldIndexDelayInfo;
import cc.telecomdigital.tdstock.model.WorldIndexInfo;
import cc.telecomdigital.tdstock.utils.Futures;
import cc.telecomdigital.tdstock.utils.Index;
import cc.telecomdigital.tdstock.utils.WorldFutures;
import cc.telecomdigital.tdstock.utils.WorldIndex;

/**
 * BMP Index
 * 
 * @author ouyangzhihui
 * 
 */
public class BMPIndexActivity extends BMPBaseActivity implements
	IScreenOrientationChangeListener
{
	List<String>							noChartList						= new ArrayList<String>();

	public String							TAG								= "BMPIndexActivity";
	private NumberFormat					_formater;
	private static final String				INDEX_NAME_HSI						= "HSI";
	private static final String				INDEX_NAME_HSCEI					= "HSCEI";

	/*-----"上証SSEI"-----by ouyangzhihui 2011-08-25---------*/
	private static final String[]				WORLD_INDEX_ITEMS_DELAY_AND_REALTIME	= {
			"SSE1", "SS300", "SSE1", "SSEA", "SSEB"							};
	/*-----"上証SSEI"-----by ouyangzhihui 2011-08-25---------*/
	private static final String[]				WORLD_INDEX_ITEMS					= {
			/* "SSE1", */"N225", "FTSE", "GDAX", "DJI", /*
														 * "SS300", "SSE1", "SSEA",
														 * "SSEB",
														 */"N225",
			"KOSPI", "STI", "TWII", "AORD", "NZTOP",
			/* "BOMBAY", */"THAI", "JKSE", "KLSE", "PHSI", "DJI", "NDX",
			"SP500", /* 隐藏印度SEN index=10 */
			"FTSE", "CAC40", "GDAX"											};

	private static final String[]				INDEX_FUTURES_ITEMS					= {
			"HSI:1", "HSI:2", "HHI:1", "HHI:2"								};
	private static final String[]				WORLD_FUTURES_ITEMS					= {
			"SSI:1", "SSI:2", "DJI:1"										};

	private static int[]					INDEX_FUTURES_LABEL_IDS;

	private static int[]					INDEX_FUTURES_LABEL_IDS_2;

	private static final String[]				INDEX_TELETEXT_ALL_ITEMS				= {
			INDEX_NAME_HSI, INDEX_NAME_HSCEI, "HSCCI", "GEM", "HSI-FIN",
			"HSI-UTL", "HSI-PRO", "HSI-CnI"									};

	private static final int[]				INDEX_CATEGORY						= {
			R.id.index_rc, R.id.index_ep, R.id.index_finance,
			R.id.index_public, R.id.index_estate, R.id.index_ic					};

	private static final int[]				INDEX_CATEGORY_LABEL				= {
			R.string.index_rc_label, R.string.index_ep_label,
			R.string.index_finance_label, R.string.index_public_label,
			R.string.index_estate_label, R.string.index_ic_label					};

	private TextView[][]					_index_category					= new TextView[6][7];

	private static final int[]				TAB_BTN_IDS						= {
			R.id.index_preset_btn, R.id.index_hk_btn, R.id.index_szsh_btn,
			R.id.index_asia_btn, R.id.index_occident_btn						};
	private Button[]						_tabBtns							= new Button[5];
	private int							_tabIndex							= 0;

	private static final String[]				WORLD_INDEX_DELAY_ITEMS				= {
			"SZEA", "SZEB"												};

	private static final int[]				WORLD_INDEX_DELAY_IDS				= {
			R.id.index_szsza, R.id.index_szszb								};

	private static final int[]				WORLD_INDEX_DELAY_LABEL				= {
			R.string.index_sza_label, R.string.index_szb_label					};

	private TextView[][]					_worldIndex_delay					= new TextView[2][7];

	// hold itemcode & adapter, index
	private static HashMap<String, Integer>		ITEM_TO_TABINDEX					= new HashMap<String, Integer>();
	static
	{
		// -----------------0--------------------
		ITEM_TO_TABINDEX.put(INDEX_NAME_HSI + IndexInfo.ADAPTER, 0); // 0 恒生指数

		ITEM_TO_TABINDEX.put(INDEX_FUTURES_ITEMS[0]
				+ IndexFuturesInfo.ADAPTER, 0); // 1恒生指数11月期货
		ITEM_TO_TABINDEX.put(INDEX_FUTURES_ITEMS[1]
				+ IndexFuturesInfo.ADAPTER, 0); // 2恒生指数12月期货

		ITEM_TO_TABINDEX.put(INDEX_NAME_HSCEI + IndexInfo.ADAPTER, 0); // 3国企指数

		ITEM_TO_TABINDEX.put(INDEX_FUTURES_ITEMS[2]
				+ IndexFuturesInfo.ADAPTER, 0); // 4国企指数11月期货
		ITEM_TO_TABINDEX.put(INDEX_FUTURES_ITEMS[3]
				+ IndexFuturesInfo.ADAPTER, 0); // 5国企指数12月期货

		ITEM_TO_TABINDEX.put(WORLD_INDEX_ITEMS_DELAY_AND_REALTIME[1], 0); // 6
																// 上证指数
		ITEM_TO_TABINDEX
				.put(WORLD_INDEX_ITEMS[0] + WorldIndexInfo.ADAPTER, 0); // 7
																// 日经指数

		ITEM_TO_TABINDEX.put(WORLD_FUTURES_ITEMS[0]
				+ WorldFuturesInfo.ADAPTER, 0); // 8日经12月
		ITEM_TO_TABINDEX.put(WORLD_FUTURES_ITEMS[1]
				+ WorldFuturesInfo.ADAPTER, 0); // 9日经3月
		ITEM_TO_TABINDEX
				.put(WORLD_INDEX_ITEMS[1] + WorldIndexInfo.ADAPTER, 0); // 10伦敦富时
		ITEM_TO_TABINDEX
				.put(WORLD_INDEX_ITEMS[2] + WorldIndexInfo.ADAPTER, 0); // 11德国DAX
		ITEM_TO_TABINDEX
				.put(WORLD_INDEX_ITEMS[3] + WorldIndexInfo.ADAPTER, 0); // 12道琼斯
		ITEM_TO_TABINDEX.put(WORLD_FUTURES_ITEMS[2]
				+ WorldFuturesInfo.ADAPTER, 0); // 13道指12月
		// -----------------0--------------------

		// -----------------1--------------------
		// ---------------分类-----------------
		ITEM_TO_TABINDEX.put(INDEX_TELETEXT_ALL_ITEMS[2], 1);
		ITEM_TO_TABINDEX.put(INDEX_TELETEXT_ALL_ITEMS[3], 1);
		ITEM_TO_TABINDEX.put(INDEX_TELETEXT_ALL_ITEMS[4], 1);
		ITEM_TO_TABINDEX.put(INDEX_TELETEXT_ALL_ITEMS[5], 1);
		ITEM_TO_TABINDEX.put(INDEX_TELETEXT_ALL_ITEMS[6], 1);
		ITEM_TO_TABINDEX.put(INDEX_TELETEXT_ALL_ITEMS[7], 1);
		// ---------------分类-----------------

		// -----------------1--------------------

		// -----------------2--------------------

		ITEM_TO_TABINDEX.put(WORLD_INDEX_ITEMS_DELAY_AND_REALTIME[1], 2);
		ITEM_TO_TABINDEX.put(WORLD_INDEX_ITEMS_DELAY_AND_REALTIME[2], 2);
		ITEM_TO_TABINDEX.put(WORLD_INDEX_ITEMS_DELAY_AND_REALTIME[3], 2);
		ITEM_TO_TABINDEX.put(WORLD_INDEX_ITEMS_DELAY_AND_REALTIME[4], 2);

		ITEM_TO_TABINDEX.put(WORLD_INDEX_DELAY_ITEMS[0]
				+ WorldIndexDelayInfo.ADAPTER, 2);
		ITEM_TO_TABINDEX.put(WORLD_INDEX_DELAY_ITEMS[1]
				+ WorldIndexDelayInfo.ADAPTER, 2);

		// -----------------2--------------------

		// -----------------3--------------------

		ITEM_TO_TABINDEX
				.put(WORLD_INDEX_ITEMS[4] + WorldIndexInfo.ADAPTER, 3);
		ITEM_TO_TABINDEX
				.put(WORLD_INDEX_ITEMS[5] + WorldIndexInfo.ADAPTER, 3);
		ITEM_TO_TABINDEX
				.put(WORLD_INDEX_ITEMS[6] + WorldIndexInfo.ADAPTER, 3);
		ITEM_TO_TABINDEX
				.put(WORLD_INDEX_ITEMS[7] + WorldIndexInfo.ADAPTER, 3);
		ITEM_TO_TABINDEX
				.put(WORLD_INDEX_ITEMS[8] + WorldIndexInfo.ADAPTER, 3);
		ITEM_TO_TABINDEX
				.put(WORLD_INDEX_ITEMS[9] + WorldIndexInfo.ADAPTER, 3);
		ITEM_TO_TABINDEX.put(WORLD_INDEX_ITEMS[10] + WorldIndexInfo.ADAPTER,
				3);
		ITEM_TO_TABINDEX.put(WORLD_INDEX_ITEMS[11] + WorldIndexInfo.ADAPTER,
				3);
		ITEM_TO_TABINDEX.put(WORLD_INDEX_ITEMS[12] + WorldIndexInfo.ADAPTER,
				3);
		ITEM_TO_TABINDEX.put(WORLD_INDEX_ITEMS[13] + WorldIndexInfo.ADAPTER,
				3);
		ITEM_TO_TABINDEX.put(WORLD_INDEX_ITEMS[14] + WorldIndexInfo.ADAPTER,
				3);
		// -----------------3--------------------

		// -----------------4--------------------
		ITEM_TO_TABINDEX.put(WORLD_INDEX_ITEMS[16] + WorldIndexInfo.ADAPTER,
				4);
		ITEM_TO_TABINDEX.put(WORLD_INDEX_ITEMS[17] + WorldIndexInfo.ADAPTER,
				4);
		ITEM_TO_TABINDEX.put(WORLD_INDEX_ITEMS[18] + WorldIndexInfo.ADAPTER,
				4);
		ITEM_TO_TABINDEX.put(WORLD_INDEX_ITEMS[19] + WorldIndexInfo.ADAPTER,
				4);
		// ITEM_TO_TABINDEX.put(WORLD_INDEX_ITEMS[20] + WorldIndexInfo.ADAPTER,
		// 4); /*隐藏印度SEN index=10*/
		// -----------------4--------------------

	}
	/*-----"上証SSEI"-----by ouyangzhihui 2011-08-25---------*/
	private static final int[]				WORLD_INDEX_DELAYREALTIME_IDS			= {
			R.id.index_preset_sse, // 上証指數
			R.id.index_szsh300, // 滬深300
			R.id.index_shsse, // 上証指數
			R.id.index_shssa, // 上海SSA
			R.id.index_shssb												// 上海SSB
																		};
	/*-----"上証SSEI"-----by ouyangzhihui 2011-08-25---------*/
	private static final int[]				WORLD_INDEX_IDS					= {
																		// R.id.index_preset_sse, // 上証指數
			R.id.index_preset_jp, // 日經指數(延遲)
			R.id.index_preset_london,// 倫敦富時(延遲)
			R.id.index_preset_dax, // 德國DAX(延遲)
			R.id.index_preset_dj, // 道瓊斯(延遲)
			// R.id.index_szsh300, // 滬深300
			// R.id.index_shsse, // 上証指數
			// R.id.index_shssa, // 上海SSA
			// R.id.index_shssb, // 上海SSB
			R.id.index_jp, // 日經指數
			R.id.index_kospi, // 南韓KOSPI
			R.id.index_sti, // 新加坡STI
			R.id.index_tai, // 加權TAI
			R.id.index_aord, // 澳洲AORD
			R.id.index_nzx, // 新西蘭NZX
			/* R.id.index_sen, */// 印度SEN /*隐藏印度SEN index=10*/
			R.id.index_set, // 曼谷SET
			R.id.index_jkt, // 椰加達JKT
			R.id.index_kls, // 吉隆坡KLS
			R.id.index_psi, // 馬尼拉PSI
			R.id.index_dj, // 道瓊斯
			R.id.index_nasd, // 納指NASD
			R.id.index_sp, // 標普S&P
			R.id.index_ftse, // 倫敦FTSE
			R.id.index_cac, // 法國CAC
			R.id.index_dax												// 德國DAX
																		};
	/*-----"上証SSEI"-----by ouyangzhihui 2011-08-25---------*/
	private static final int[]				WORLD_INDEX_DELAYREALTIME_LABEL_IDS	= {
			R.string.index_sse1_label, R.string.index_ss300_label,
			R.string.index_sse1_label, R.string.index_ssea_label,
			R.string.index_sseb_label										};
	/*-----"上証SSEI"-----by ouyangzhihui 2011-08-25---------*/
	private static final int[]				WORLD_INDEX_LABEL_IDS				= {
			/* R.string.index_sse1_label, */R.string.index_n225_label,
			R.string.index_ftse_label, R.string.index_gdax_label,
			R.string.index_dji_label, /*
									 * R.string.index_ss300_label,
									 * R.string.index_sse1_label,
									 * R.string.index_ssea_label,
									 * R.string.index_sseb_label,
									 */R.string.index_n225_label_2,
			R.string.index_kospi_label, R.string.index_sti_label,
			R.string.index_twii_label, R.string.index_aord_label,
			R.string.index_nztop_label, /* R.string.index_bombay_label, *//*
																		 * 隐藏印度SEN
																		 * index
																		 * =10
																		 */
			R.string.index_thai_label, R.string.index_jkse_label,
			R.string.index_klse_label, R.string.index_phsi_label,
			R.string.index_dji_label_2, R.string.index_ndx_label,
			R.string.index_sp500_label, R.string.index_ftse_label_2,
			R.string.index_cac40_label, R.string.index_gdax_label_2,				};

	private static final String[]				TAGS								= {
			"index_value", "index_net", "index_net_percentage",
			"index_high", "index_low", "index_open", "index_prev"					};
	private static final String				REPLACEMENT_TAG					= "replacement_tag";
	private static final String				NAME_TAG							= "index_name";
	private static final String				NAME_ADDTO_MONITOR_TAG				= "addto_monitor_tag";
	private final static String				TAG_CHART							= "fx_chart";

	// private final static int[] IDS_TAB_PANEL = {R.id.index_preset_tab,
	// R.id.index_szsh_tab,R.id.index_asia_tab, R.id.index_occident_tab,
	// R.id.index_category_tab};
	private final static int[]				IDS_TAB_PANEL						= {
			R.id.index_preset_tab, R.id.index_hk_tab, R.id.index_szsh_tab,
			R.id.index_asia_tab, R.id.index_occident_tab						};

	private TextView[][]					_index_hsi_views					= new TextView[2][7];
	private TextView[][]					_index_hscei_views					= new TextView[2][7];
	private TextView[][][]					_index_futures_views				= new TextView[2][7][7];		// the
																									// first
																									// four
																									// is
																									// futures,
																									// the
																									// left
																									// is
																									// world
																									// futures;
	/*-----"上証SSEI"-----by ouyangzhihui 2011-08-25---------*/
	private TextView[][]					_world_index_delay_realtime_views		= new TextView[5][7];
	/*-----"上証SSEI"-----by ouyangzhihui 2011-08-25---------*/
	private TextView[][]					_world_index_views					= new TextView[21 - 1][7];		/*
																											 * 隐藏印度SEN
																											 * index=10
																											 */

	private TextView						_top_bar_title;

	public final static int					BUFFERED_READER_SIZE				= 24 * 1024;					// 24K;

	private ImageView						_chartImg							= null;

	private static Integer					CHART_IMG_TAG_FOR_KEY				= R.id.index_preset_sse;
	private static Integer					CHART_IMG_TAG_FOR_CLICK				= R.id.index_dax;

	private static HashMap<Integer, Integer>	TAB4And5Map						= new HashMap<Integer, Integer>();
	private static HashMap<Integer, Integer>	TAB1And3Map						= new HashMap<Integer, Integer>();
	private static HashMap<Integer, Integer>	TAB1And2Map						= new HashMap<Integer, Integer>();
	static
	{
		TAB1And2Map.put(R.id.index_phsi_current_month, 1);
		TAB1And2Map.put(R.id.index_phsi_next_month, 1);
		TAB1And2Map.put(R.id.index_hscei_current_month, 1);
		TAB1And2Map.put(R.id.index_hscei_next_month, 1);
	}
	static
	{

		TAB1And3Map.put(R.id.index_preset_sse, 1);

		TAB1And3Map.put(R.id.index_szsh300, 3);
		TAB1And3Map.put(R.id.index_shsse, 3);
		TAB1And3Map.put(R.id.index_shssa, 3);
		TAB1And3Map.put(R.id.index_shssb, 3);
	}
	static
	{

		TAB4And5Map.put(R.id.index_preset_jp, 1);
		TAB4And5Map.put(R.id.index_jp_later_month, 1);
		TAB4And5Map.put(R.id.index_jp_more_later_month, 1);
		TAB4And5Map.put(R.id.index_preset_london, 1);
		TAB4And5Map.put(R.id.index_preset_dax, 1);
		TAB4And5Map.put(R.id.index_preset_dj, 1);
		TAB4And5Map.put(R.id.index_dj_later_month, 1);

		TAB4And5Map.put(R.id.index_szsza, 3);
		TAB4And5Map.put(R.id.index_szszb, 3);

		TAB4And5Map.put(R.id.index_jp, 4);
		TAB4And5Map.put(R.id.index_jp_later_month, 4);
		TAB4And5Map.put(R.id.index_jp_more_later_month, 4);
		TAB4And5Map.put(R.id.index_kospi, 4);
		TAB4And5Map.put(R.id.index_sti, 4);
		TAB4And5Map.put(R.id.index_tai, 4);
		TAB4And5Map.put(R.id.index_aord, 4);
		TAB4And5Map.put(R.id.index_nzx, 4);
		// TAB4And5Map.put( R.id.index_sen, 4);/*隐藏印度SEN index=10*/
		TAB4And5Map.put(R.id.index_set, 4);
		TAB4And5Map.put(R.id.index_jkt, 4);
		TAB4And5Map.put(R.id.index_kls, 4);
		TAB4And5Map.put(R.id.index_psi, 4);

		TAB4And5Map.put(R.id.index_dj, 5);
		TAB4And5Map.put(R.id.index_dj_later_month, 5);
		TAB4And5Map.put(R.id.index_nasd, 5);
		TAB4And5Map.put(R.id.index_sp, 5);
		TAB4And5Map.put(R.id.index_ftse, 5);
		TAB4And5Map.put(R.id.index_cac, 5);
		TAB4And5Map.put(R.id.index_dax, 5);
	}

	// protected IndexAsyncTask indexAsyncTask;

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		TDStockLog.d(TAG, TAG + " onCreate");

		setContentView(R.layout.index);

		initHasChartList();

		_formater = DecimalFormat.getInstance();
		_formater.setMaximumFractionDigits(0);
		// _formater.setMinimumFractionDigits(2);

		_top_bar_title = (TextView) findViewById(R.id.top_bar_title);

		Button _btn_update_data = (Button) findViewById(R.id._btn_update_data);
		_btn_update_data.setVisibility(View.VISIBLE);
		_btn_update_data.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				TDStockLog.d(TAG, "BMP update data");

				loadDataUpdateUI(_tabIndex, "false");
			}
		});

		Button _toolbutton_options = (Button) findViewById(R.id.options_btn);
		_toolbutton_options.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				TDStockLog.d(TAG,
						"close current activity and forwarding to the previous");

				Intent intent = new Intent(getApplicationContext(),
						IndexOptionsListActivity.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
						| Intent.FLAG_ACTIVITY_NO_USER_ACTION);
				SwitchForwardActivity(IndexOptionsListActivity.class,
						intent);
			}
		});

		initTabButtons();

		// "期指Futures"，"上証SSEI" set Adapter
		// initFuturesAndSSEIAdapterType();
		initIndexViews();
		isChangeModeType = false;
	}

	public static boolean	isChangeModeType	= false;

	private void initTabButtons()
	{
		// final ViewGroup tab = (ViewGroup)findViewById(R.id.mock_tab);
		for (int index = 0, count = TAB_BTN_IDS.length; index < count; index++)
		{
			_tabBtns[index] = (Button) findViewById(TAB_BTN_IDS[index]);
		}
		for (int index = 0, count = /* tab.getChildCount() */TAB_BTN_IDS.length; index < count; index++)
		{
			final Button btn = /* (Button)tab.getChildAt(index); */_tabBtns[index];
			final int currentIndex = index;
			final int btnCount = count;
			btn.setWidth((_display.getWidth() - count - 1) / count);
			btn.setOnClickListener(new OnClickListener()
			{
				@Override
				public void onClick(View v)
				{
					final Runnable myUpdateResults = new Runnable()
					{
						public void run()
						{
							if (currentIndex == 3 || currentIndex == 4)
							{
								_top_bar_title
										.setText(getResources()
												.getString(
														R.string.index_delay));
							}
							else
							{
								_top_bar_title.setText(getResources()
										.getString(R.string.index));
							}

							for (int item = 0, itemCount = TAB_BTN_IDS.length; item < itemCount; item++)
							{
								Button tmpBtn = _tabBtns[item];
								if (item != 0 && item != itemCount - 1)
								{
									tmpBtn.setBackgroundDrawable(null);
									tmpBtn.setBackgroundColor(0xfff1f1f1);
								}
								else
								{
									tmpBtn.setBackgroundDrawable(null);
									tmpBtn.setBackgroundResource(item == 0 ? R.drawable.rect_left_grey
											: R.drawable.rect_right_grey);
								}
								tmpBtn.setTextColor(R.color.grey);

								ViewGroup tmpView = (ViewGroup) findViewById(IDS_TAB_PANEL[item]);
								tmpView.setVisibility(View.GONE);
							}
							btn.setBackgroundResource(currentIndex == 0 ? R.drawable.gradient_rect_left
									: (currentIndex == btnCount - 1 ? R.drawable.gradient_rect_right
											: R.drawable.gradient_rect));
							btn.setTextColor(Color.WHITE);

							ViewGroup tmpView = (ViewGroup) findViewById(IDS_TAB_PANEL[currentIndex]);
							tmpView.setVisibility(View.VISIBLE);
							tmpView.postInvalidate();

							_tabIndex = currentIndex;
							// if(indexAsyncTask != null)
							// {
							// indexAsyncTask.cancel(true);
							// indexAsyncTask = null;
							// }
							loadDataUpdateUI(_tabIndex);
						}
					};
					new Thread()
					{
						public void run()
						{
							if (_messageHandler != null)
								_messageHandler.post(myUpdateResults);
						}
					}.start();
				}
			});
		}
	}

	private void initIndexViews()
	{
		/*------------------------*/
		int index_futures_hsi_later_label = R.string.index_futures_hsi_later_label;
		int index_hscei_later_label = R.string.index_hscei_later_label;
		// account login svcPlan2=0
		if (!((ITDLApplication) getApplicationContext())
				.getIsRealtimeFutures())
		{
			index_futures_hsi_later_label = R.string.index_futures_hsi_morelater_label;
			index_hscei_later_label = R.string.index_hscei_morelater_label;
		}
		INDEX_FUTURES_LABEL_IDS = new int[] { index_futures_hsi_later_label,
				index_futures_hsi_later_label, index_hscei_later_label,
				index_hscei_later_label, R.string.index_n225_later_label,
				R.string.index_n225_later_label,
				R.string.index_dji_later_label };
		INDEX_FUTURES_LABEL_IDS_2 = new int[] {
				index_futures_hsi_later_label,
				index_futures_hsi_later_label, index_hscei_later_label,
				index_hscei_later_label,
				R.string.index_n225_morelater_label,
				R.string.index_n225_morelater_label,
				R.string.index_dji_morelater_label };
		/*------------------------*/

		ViewGroup tab1Container = (ViewGroup) findViewById(IDS_TAB_PANEL[0]);
		ViewGroup tab2Container = (ViewGroup) findViewById(IDS_TAB_PANEL[1]);
		ViewGroup[] tabContainer = { tab1Container, tab2Container };

		for (int index = 0; index < 2; index++)
		{

			ViewGroup index_container = (ViewGroup) tabContainer[index]
					.findViewById(R.id.index_phsi);
			if (index_container != null)
			{
				// ((TextView)index_container.findViewWithTag(NAME_TAG)).setText(R.string.index_hsi_label);
				String nameRes = getResources().getString(
						R.string.index_hsi_label);
				((TextView) index_container.findViewWithTag(NAME_TAG))
						.setText(Html.fromHtml(nameRes));
				changeIndexNameTextForDelayData(index_container);

				((TextView) index_container
						.findViewWithTag(REPLACEMENT_TAG))
						.setText(R.string.index_turnover);
				Button addToMonitor = (Button) index_container
						.findViewWithTag(NAME_ADDTO_MONITOR_TAG);
				ViewGroup addToMonitor_container = (ViewGroup) index_container
						.findViewWithTag("addto_monitor_tag_container");
				if (addToMonitor != null)
				{
					AddIndexClickHandler handler = new AddIndexClickHandler(
							this);
					handler.setAdapter(IndexInfo.ADAPTER);
					handler.setItem(INDEX_NAME_HSI);
					handler.setFields(
							getResources().getString(
									R.string.index_hsi_label),
							IndexInfo.INDEXLAST, IndexInfo.INDEXNET, "");
					addToMonitor.setOnClickListener(handler);
					addToMonitor_container.setOnClickListener(handler);
				}

				ImageView imageView = (ImageView) index_container
						.findViewWithTag(TAG_CHART);
				if (imageView != null)
				{
					imageView.setVisibility(isShouldShowImg(INDEX_NAME_HSI) ? View.VISIBLE
							: View.GONE);
					imageView.setClickable(true);
					imageView.setFocusable(true);
					imageView.setTag(CHART_IMG_TAG_FOR_KEY, INDEX_NAME_HSI);

					/*
					 * imageView.setOnClickListener(new ForwardToChart(
					 * INDEX_NAME_HSI, getResources().getString(
					 * R.string.index_hsi_label), index_container));
					 */

					imageView.setTag(
							CHART_IMG_TAG_FOR_CLICK,
							new ForwardToChart(
									INDEX_NAME_HSI,
									getResources()
											.getString(
													R.string.index_hsi_label),
									index_container)); // modified by haibo,
													// 2011-07-28, avoid to
													// click the image to
													// enter chart

					// add description too see chart
					rotateToseeChart(index_container);
					// add description too see chart

				}

				for (int item = 0, count = TAGS.length; item < count; item++)
				{
					// each index has a tag
					_index_hsi_views[index][item] = (TextView) index_container
							.findViewWithTag(TAGS[item]);
				}
			}

		}

		for (int index = 0; index < 2; index++)
		{

			ViewGroup hscei_container = (ViewGroup) tabContainer[index]
					.findViewById(R.id.index_hscei);
			if (hscei_container != null)
			{
				// ((TextView)hscei_container.findViewWithTag(NAME_TAG)).setText(R.string.index_hscei_label);
				String nameRes = getResources().getString(
						R.string.index_hscei_label);
				((TextView) hscei_container.findViewWithTag(NAME_TAG))
						.setText(nameRes);

				changeIndexNameTextForDelayData(hscei_container);
				Button addToMonitor = (Button) hscei_container
						.findViewWithTag(NAME_ADDTO_MONITOR_TAG);
				ViewGroup addToMonitor_container = (ViewGroup) hscei_container
						.findViewWithTag("addto_monitor_tag_container");
				if (addToMonitor != null)
				{
					AddIndexClickHandler handler = new AddIndexClickHandler(
							this);
					handler.setAdapter(IndexInfo.ADAPTER);
					handler.setItem(INDEX_NAME_HSCEI);
					handler.setFields(
							getResources().getString(
									R.string.index_hscei_label),
							IndexInfo.INDEXLAST, IndexInfo.INDEXNET, "");
					addToMonitor.setOnClickListener(handler);
					addToMonitor_container.setOnClickListener(handler);
				}

				ImageView imageView = (ImageView) hscei_container
						.findViewWithTag(TAG_CHART);
				if (imageView != null)
				{
					imageView.setVisibility(isShouldShowImg(INDEX_NAME_HSCEI) ? View.VISIBLE
							: View.GONE);
					imageView.setClickable(true);
					imageView.setFocusable(true);
					imageView.setTag(CHART_IMG_TAG_FOR_KEY,
							INDEX_NAME_HSCEI);

					// --------modified by haibo, 2011-07-28, avoid to click the
					// image to enter chart-----------
					/*
					 * imageView.setOnClickListener(new ForwardToChart(
					 * INDEX_NAME_HSCEI, getResources().getString(
					 * R.string.index_hscei_label), hscei_container));
					 */

					imageView.setTag(
							CHART_IMG_TAG_FOR_CLICK,
							new ForwardToChart(
									INDEX_NAME_HSCEI,
									getResources()
											.getString(
													R.string.index_hscei_label),
									hscei_container));

					// --------modified by haibo, 2011-07-28, avoid to click the
					// image to enter chart-----------

					// add description too see chart
					rotateToseeChart(hscei_container);
					// add description too see chart

				}
				// each index has a tag
				for (int item = 0, count = TAGS.length; item < count; item++)
				{
					_index_hscei_views[index][item] = (TextView) hscei_container
							.findViewWithTag(TAGS[item]);
				}
			}

		}

		int[] ids_futures = { R.id.index_phsi_current_month,
				R.id.index_phsi_next_month, R.id.index_hscei_current_month,
				R.id.index_hscei_next_month, R.id.index_jp_later_month,
				R.id.index_jp_more_later_month, R.id.index_dj_later_month };

		ViewGroup[] tabContainerOnFutures = new ViewGroup[2];
		tabContainerOnFutures[0] = (ViewGroup) findViewById(IDS_TAB_PANEL[0]); // all
																	// items
																	// on
																	// the
																	// first
																	// tab
		tabContainerOnFutures[1] = (ViewGroup) findViewById(IDS_TAB_PANEL[1]); // set
																	// default
																	// tab(
																	// the
																	// secondary
																	// tab)
		for (int index = 0, count = ids_futures.length; index < count; index++)
		{
			int index_futures_label_ids = INDEX_FUTURES_LABEL_IDS[index];
			switch (index)
			{
				case 4:
				case 5:
					tabContainerOnFutures[1] = (ViewGroup) findViewById(IDS_TAB_PANEL[3]); // set
																				// tab
																				// as
																				// the
																				// third
					break;
				case 6:
					tabContainerOnFutures[1] = (ViewGroup) findViewById(IDS_TAB_PANEL[4]); // set
																				// tab
																				// as
																				// the
																				// fourth
					break;
				default:
					break; // have been set in the outside of the looper
			}

			for (int tab = 0; tab < 2; tab++)
			{

				ViewGroup container = (ViewGroup) tabContainerOnFutures[tab]
						.findViewById(ids_futures[index]);
				/*------------- by ouyangzhihui 2011-08-24 ------------*/
				if (((ITDLApplication) getApplicationContext())
						.getDataMode() == DataMode.Delay)
				{
					index_futures_label_ids = INDEX_FUTURES_LABEL_IDS[index];
				}
				else
				{
					if (tab == 0)
					{
						index_futures_label_ids = INDEX_FUTURES_LABEL_IDS_2[index];
					}
					else
					{
						index_futures_label_ids = INDEX_FUTURES_LABEL_IDS[index];
					}
				}
				String nameRes = getResources().getString(
						index_futures_label_ids, "--");
				((TextView) container.findViewWithTag(NAME_TAG))
						.setText(Html.fromHtml(nameRes));

				changeIndexNameTextForDelayData(container);
				/*------------- by ouyangzhihui 2011-08-24 -----------*/

				if (tab == 0 && index > 3) // 预设：日經指數上月期貨,日經指數下月期貨,道瓊斯本月期貨
				{
					container.findViewWithTag(REPLACEMENT_TAG)
							.setVisibility(View.GONE);
				}
				else if (tab > 0 && index > 3) // tab 4,5:
											// 日經指數上月期貨,日經指數下月期貨,道瓊斯本月期貨
				{
					((TextView) container.findViewWithTag(REPLACEMENT_TAG))
							.setText(R.string.index_prev);
				}
				else
				{
					((TextView) container.findViewWithTag(REPLACEMENT_TAG))
							.setText(R.string.index_sharetraded);
				}

				Button addToMonitor = (Button) container
						.findViewWithTag(NAME_ADDTO_MONITOR_TAG);
				ViewGroup addToMonitor_container = (ViewGroup) container
						.findViewWithTag("addto_monitor_tag_container");
				if (addToMonitor != null)
				{
					AddIndexClickHandler handler = new AddIndexClickHandler(
							this);
					handler.setAdapter(index <= 3 ? IndexFuturesInfo.ADAPTER
							: WorldFuturesInfo.ADAPTER);
					handler.setItem(index <= 3 ? INDEX_FUTURES_ITEMS[index]
							: WORLD_FUTURES_ITEMS[index - 4]);
					handler.setFields("", "", "", "");
					addToMonitor.setOnClickListener(handler);
					addToMonitor_container.setOnClickListener(handler);
				}
				ImageView imageView = (ImageView) container
						.findViewWithTag(TAG_CHART);
				if (imageView != null)
				{
					imageView.setVisibility(isShouldShowImg(index <= 3 ? INDEX_FUTURES_ITEMS[index]
							: WORLD_FUTURES_ITEMS[index - 4]) ? View.VISIBLE
							: View.GONE);
					imageView.setClickable(true);
					imageView.setFocusable(true);
					imageView.setTag(CHART_IMG_TAG_FOR_KEY,
							index <= 3 ? INDEX_FUTURES_ITEMS[index]
									: WORLD_FUTURES_ITEMS[index - 4]);

					// --------modified by haibo, 2011-07-28, avoid to click the
					// image to enter chart-----------

					/*
					 * imageView.setOnClickListener(new ForwardToChart( index <=
					 * 3 ? INDEX_FUTURES_ITEMS[index] :
					 * WORLD_FUTURES_ITEMS[index - 4], null, container));
					 */

					imageView.setTag(
							CHART_IMG_TAG_FOR_CLICK,
							new ForwardToChart(
									index <= 3 ? INDEX_FUTURES_ITEMS[index]
											: WORLD_FUTURES_ITEMS[index - 4],
									null, container));

					// --------modified by haibo, 2011-07-28, avoid to click the
					// image to enter chart-----------

					// add description too see chart
					rotateToseeChart(container);
					// add description too see chart

				}

				TextView[] holder = _index_futures_views[tab][index];
				for (int item = 0, itemCount = TAGS.length; item < itemCount; item++)
				{
					// each index has a tag
					holder[item] = (TextView) container
							.findViewWithTag(TAGS[item]);
				}
				if (tab == 0 && index > 3)
				{
					holder[6].setVisibility(View.GONE);
				}
			}

		}
		/*-----上証（SSEI）----*/
		for (int index = 0, count = WORLD_INDEX_DELAYREALTIME_IDS.length; index < count; index++)
		{
			ViewGroup container = (ViewGroup) findViewById(WORLD_INDEX_DELAYREALTIME_IDS[index]);
			TextView[] holder = _world_index_delay_realtime_views[index];

			// ((TextView)container.findViewWithTag(NAME_TAG)).setText(WORLD_INDEX_LABEL_IDS[index]);

			String nameRes = getResources().getString(
					WORLD_INDEX_DELAYREALTIME_LABEL_IDS[index]);
			((TextView) container.findViewWithTag(NAME_TAG)).setText(Html
					.fromHtml(nameRes));

			changeIndexNameTextForDelayData(container);

			Button addToMonitor = (Button) container
					.findViewWithTag(NAME_ADDTO_MONITOR_TAG);
			ViewGroup addToMonitor_container = (ViewGroup) container
					.findViewWithTag("addto_monitor_tag_container");
			if (addToMonitor != null)
			{
				AddIndexClickHandler handler = new AddIndexClickHandler(
						this);
				handler.setAdapter(WorldIndexInfo.ADAPTER
						+ WorldIndexDelayInfo.ADAPTER); // "上証SSEI"
				handler.setItem(WORLD_INDEX_ITEMS_DELAY_AND_REALTIME[index]);
				handler.setFields(
						getResources()
								.getString(
										WORLD_INDEX_DELAYREALTIME_LABEL_IDS[index]),
						WorldIndexInfo.LAST, WorldIndexInfo.NET,
						WorldIndexInfo.NETPERCENTAGE);
				addToMonitor.setOnClickListener(handler);
				addToMonitor_container.setOnClickListener(handler);
			}

			ImageView imageView = (ImageView) container
					.findViewWithTag(TAG_CHART);
			if (imageView != null)
			{
				imageView.setVisibility(isShouldShowImg(WORLD_INDEX_ITEMS_DELAY_AND_REALTIME[index]) ? View.VISIBLE
						: View.GONE);
				imageView.setClickable(true);
				imageView.setFocusable(true);
				imageView.setTag(CHART_IMG_TAG_FOR_KEY,
						WORLD_INDEX_ITEMS_DELAY_AND_REALTIME[index]);

				// --------modified by haibo, 2011-07-28, avoid to click the
				// image to enter chart-----------
				/*
				 * imageView.setOnClickListener(new ForwardToChart(
				 * WORLD_INDEX_ITEMS[index], getResources().getString(
				 * WORLD_INDEX_LABEL_IDS[index]), container));
				 */

				imageView.setTag(
						CHART_IMG_TAG_FOR_CLICK,
						new ForwardToChart(
								WORLD_INDEX_ITEMS_DELAY_AND_REALTIME[index],
								getResources()
										.getString(
												WORLD_INDEX_DELAYREALTIME_LABEL_IDS[index]),
								container));

				// --------modified by haibo, 2011-07-28, avoid to click the
				// image to enter chart-----------

				// add description too see chart
				rotateToseeChart(container);
				// add description too see chart

			}

			for (int item = 0, itemCount = holder.length; item < itemCount; item++)
			{
				// each index has a tag
				holder[item] = (TextView) container
						.findViewWithTag(TAGS[item]);
			}

		}
		/*-----------------end--------*/

		for (int index = 0, count = WORLD_INDEX_IDS.length; index < count; index++)
		{
			ViewGroup container = (ViewGroup) findViewById(WORLD_INDEX_IDS[index]);
			TextView[] holder = _world_index_views[index];

			// ((TextView)container.findViewWithTag(NAME_TAG)).setText(WORLD_INDEX_LABEL_IDS[index]);

			String nameRes = getResources().getString(
					WORLD_INDEX_LABEL_IDS[index]);
			((TextView) container.findViewWithTag(NAME_TAG)).setText(Html
					.fromHtml(nameRes));

			changeIndexNameTextForDelayData(container);

			Button addToMonitor = (Button) container
					.findViewWithTag(NAME_ADDTO_MONITOR_TAG);
			ViewGroup addToMonitor_container = (ViewGroup) container
					.findViewWithTag("addto_monitor_tag_container");
			if (addToMonitor != null)
			{
				AddIndexClickHandler handler = new AddIndexClickHandler(
						this);
				handler.setAdapter(WorldIndexInfo.ADAPTER);
				handler.setItem(WORLD_INDEX_ITEMS[index]);
				handler.setFields(
						getResources().getString(
								WORLD_INDEX_LABEL_IDS[index]),
						WorldIndexInfo.LAST, WorldIndexInfo.NET,
						WorldIndexInfo.NETPERCENTAGE);
				addToMonitor.setOnClickListener(handler);
				addToMonitor_container.setOnClickListener(handler);
			}

			ImageView imageView = (ImageView) container
					.findViewWithTag(TAG_CHART);
			if (imageView != null)
			{
				imageView.setVisibility(isShouldShowImg(WORLD_INDEX_ITEMS[index]) ? View.VISIBLE
						: View.GONE);
				imageView.setClickable(true);
				imageView.setFocusable(true);
				imageView.setTag(CHART_IMG_TAG_FOR_KEY,
						WORLD_INDEX_ITEMS[index]);

				// --------modified by haibo, 2011-07-28, avoid to click the
				// image to enter chart-----------
				/*
				 * imageView.setOnClickListener(new ForwardToChart(
				 * WORLD_INDEX_ITEMS[index], getResources().getString(
				 * WORLD_INDEX_LABEL_IDS[index]), container));
				 */

				imageView.setTag(
						CHART_IMG_TAG_FOR_CLICK,
						new ForwardToChart(
								WORLD_INDEX_ITEMS[index],
								getResources().getString(
										WORLD_INDEX_LABEL_IDS[index]),
								container));

				// --------modified by haibo, 2011-07-28, avoid to click the
				// image to enter chart-----------

				// add description too see chart
				rotateToseeChart(container);
				// add description too see chart

			}

			for (int item = 0, itemCount = holder.length; item < itemCount; item++)
			{
				// each index has a tag
				holder[item] = (TextView) container
						.findViewWithTag(TAGS[item]);
			}

		}

		for (int index = 0, count = INDEX_CATEGORY.length; index < count; index++)
		{
			ViewGroup container = (ViewGroup) findViewById(INDEX_CATEGORY[index]);
			TextView[] holder = _index_category[index];
			String nameRes = getResources().getString(
					INDEX_CATEGORY_LABEL[index]);
			// ((TextView)container.findViewWithTag(NAME_TAG)).setText(INDEX_CATEGORY_LABEL[index]);
			((TextView) container.findViewWithTag(NAME_TAG)).setText(Html
					.fromHtml(nameRes));

			changeIndexNameTextForDelayData(container);
			Button addToMonitor = (Button) container
					.findViewWithTag(NAME_ADDTO_MONITOR_TAG);
			ViewGroup addToMonitor_container = (ViewGroup) container
					.findViewWithTag("addto_monitor_tag_container");
			if (addToMonitor != null)
			{
				AddIndexClickHandler handler = new AddIndexClickHandler(
						this);
				handler.setAdapter(IndexInfo.ADAPTER);
				handler.setItem(INDEX_TELETEXT_ALL_ITEMS[index + 2]);
				handler.setFields(
						getResources().getString(
								INDEX_CATEGORY_LABEL[index]),
						IndexInfo.INDEXLAST, IndexInfo.INDEXNET, "");
				addToMonitor.setOnClickListener(handler);
				addToMonitor_container.setOnClickListener(handler);
			}

			ImageView imageView = (ImageView) container
					.findViewWithTag(TAG_CHART);
			if (imageView != null)
			{
				imageView.setVisibility(isShouldShowImg(INDEX_TELETEXT_ALL_ITEMS[index + 2]) ? View.VISIBLE
						: View.GONE);
				imageView.setClickable(true);
				imageView.setFocusable(true);
				imageView.setTag(CHART_IMG_TAG_FOR_KEY,
						INDEX_TELETEXT_ALL_ITEMS[index + 2]);

				// --------modified by haibo, 2011-07-28, avoid to click the
				// image to enter chart-----------
				/*
				 * imageView .setOnClickListener(new ForwardToChart(
				 * INDEX_TELETEXT_ALL_ITEMS[index + 2],
				 * getResources().getString( INDEX_CATEGORY_LABEL[index]),
				 * container));
				 */

				imageView.setTag(
						CHART_IMG_TAG_FOR_CLICK,
						new ForwardToChart(
								INDEX_TELETEXT_ALL_ITEMS[index + 2],
								getResources().getString(
										INDEX_CATEGORY_LABEL[index]),
								container));

				// --------modified by haibo, 2011-07-28, avoid to click the
				// image to enter chart-----------

				// add description too see chart
				rotateToseeChart(container);
				// add description too see chart

			}

			for (int item = 0, itemCount = holder.length; item < itemCount; item++)
			{
				// each index has a tag
				holder[item] = (TextView) container
						.findViewWithTag(TAGS[item]);
			}
		}

		for (int index = 0, count = WORLD_INDEX_DELAY_IDS.length; index < count; index++)
		{
			ViewGroup container = (ViewGroup) findViewById(WORLD_INDEX_DELAY_IDS[index]);
			TextView[] holder = _worldIndex_delay[index];
			// ((TextView)container.findViewWithTag(NAME_TAG)).setText(WORLD_INDEX_DELAY_LABEL[index]);
			String nameRes = getResources().getString(
					WORLD_INDEX_DELAY_LABEL[index]);
			((TextView) container.findViewWithTag(NAME_TAG)).setText(Html
					.fromHtml(nameRes));

			changeIndexNameTextForDelayData(container);
			Button addToMonitor = (Button) container
					.findViewWithTag(NAME_ADDTO_MONITOR_TAG);
			ViewGroup addToMonitor_container = (ViewGroup) container
					.findViewWithTag("addto_monitor_tag_container");
			if (addToMonitor != null)
			{
				AddIndexClickHandler handler = new AddIndexClickHandler(
						this);
				handler.setAdapter(WorldIndexDelayInfo.ADAPTER);
				handler.setItem(WORLD_INDEX_DELAY_ITEMS[index]);

				handler.setFields(
						getResources().getString(
								WORLD_INDEX_DELAY_LABEL[index]),
						WorldIndexDelayInfo.LAST,
						WorldIndexDelayInfo.NET,
						WorldIndexDelayInfo.NETPERCENTAGE);
				addToMonitor.setOnClickListener(handler);
				addToMonitor_container.setOnClickListener(handler);
			}

			ImageView imageView = (ImageView) container
					.findViewWithTag(TAG_CHART);
			if (imageView != null)
			{
				imageView.setVisibility(isShouldShowImg(WORLD_INDEX_DELAY_ITEMS[index]) ? View.VISIBLE
						: View.GONE);
				imageView.setClickable(true);
				imageView.setFocusable(true);
				imageView.setTag(CHART_IMG_TAG_FOR_KEY,
						WORLD_INDEX_DELAY_ITEMS[index]);

				// --------modified by haibo, 2011-07-28, avoid to click the
				// image to enter chart-----------
				/*
				 * imageView.setOnClickListener(new ForwardToChart(
				 * WORLD_INDEX_DELAY_ITEMS[index], getResources().getString(
				 * WORLD_INDEX_DELAY_LABEL[index]), container));
				 */

				imageView.setTag(
						CHART_IMG_TAG_FOR_CLICK,
						new ForwardToChart(
								WORLD_INDEX_DELAY_ITEMS[index],
								getResources()
										.getString(
												WORLD_INDEX_DELAY_LABEL[index]),
								container));

				// --------modified by haibo, 2011-07-28, avoid to click the
				// image to enter chart-----------

				// add description too see chart
				rotateToseeChart(container);
				// add description too see chart

			}

			for (int item = 0, itemCount = holder.length; item < itemCount; item++)
			{
				// each index has a tag
				holder[item] = (TextView) container
						.findViewWithTag(TAGS[item]);
			}
		}
	}

	private void rotateToseeChart(ViewGroup container)
	{
		// add description too see chart
		container.setOnFocusChangeListener(new OnFocusChangeListener()
		{
			@Override
			public void onFocusChange(View v, boolean hasFocus)
			{
				TextView rotateToSeeChart = (TextView) (((ViewGroup) v)
						.findViewWithTag("rotate_to_see_chart"));
				ImageView imageView = (ImageView) (((ViewGroup) v)
						.findViewWithTag(TAG_CHART));
				if (rotateToSeeChart != null)
				{
					rotateToSeeChart.setVisibility(hasFocus
							&& (imageView != null)
							&& (imageView.getVisibility() == View.VISIBLE) ? View.VISIBLE
							: View.GONE);
					_chartImg = imageView;
				}
			}

		});

		ImageView imageView = (ImageView) (container
				.findViewWithTag(TAG_CHART));
		if ((imageView != null)
				&& (imageView.getVisibility() != View.VISIBLE))
		{
			container.setBackgroundResource(R.drawable.backgound_states_4_no_chart);
		}
	}

	// @Override
	// public void onConfigurationChanged(Configuration newConfig)
	// {
	// forwardToChartActivity();
	//
	// super.onConfigurationChanged(newConfig);
	// }

	public void resetTabBtnWidth()
	{
		for (int index = 0, count = TAB_BTN_IDS.length; index < count; index++)
		{
			_tabBtns[index] = (Button) findViewById(TAB_BTN_IDS[index]);
			_tabBtns[index].setWidth((_display.getWidth() - count - 1)
					/ count);
		}
	}

	private class AddIndexClickHandler extends DefaultClickHandler
	{
		private String	_item;
		private String	_adapter;
		private String	_fieldName;
		private String	_fieldValue;
		private String	_fieldNet;
		private String	_fieldNetPercentage;
		private String	_iconName;

		public AddIndexClickHandler(Context context)
		{
			super(context);
		}

		public void setItem(String item)
		{
			_item = item;
		}

		public void setIconName(String icnName)
		{
			_iconName = icnName;
		}

		public void setAdapter(String adapter)
		{
			_adapter = adapter;
		}

		public void setFields(String name, String value, String net,
				String netpercentage)
		{
			_fieldName = name;
			_fieldValue = value;
			_fieldNet = net;
			_fieldNetPercentage = netpercentage;
		}

		@Override
		protected void onDefaultAction()
		{

/*			DBHelper dbHelper = new DBHelper(BMPIndexActivity.this);
			try
			{*/
				// int customerId = ((ITDLApplication) getApplicationContext())
				// .getUserId(-1);
				// mode is delay
				/*
				 * if(((ITDLApplication)getApplicationContext()).getModeType()==
				 * CommonDefn.ModeType.DELARY){ if
				 * (dbHelper.isSubscribeItemExist(customerId, _item, _adapter))
				 * { new CustomizeDialog(getMyOwnContext(), "",
				 * getResources().getString
				 * (R.string.monitor_exist_index)).show(); } else if
				 * (dbHelper.isFullWithItemInMonitor(customerId)) { new
				 * CustomizeDialog(getMyOwnContext(), "",
				 * getResources().getString
				 * (R.string.monitor_is_full_with_items)).show(); } else { long
				 * result = dbHelper.insertSubscribeItem(customerId, _item,
				 * _adapter, _fieldName, _fieldValue, _fieldNet,
				 * _fieldNetPercentage);
				 * 
				 * if (result > 0) { modify by zor(ouyangzhihui) String temp =
				 * _iconName == null ? _item.substring(0, 2) : _iconName; temp =
				 * _item.length() >= 2 ? _item.substring(0, 2) : _item;
				 * startAnimat(temp); }
				 * 
				 * TDStockLog.d(TAG, "insert result:" + result); } }
				 */
				// mode is not delay
				// else{
				/*
				 * if(MonitorUtil.getInstance().addBookMarkItem( _item,
				 * CommonDefn
				 * .BookMarkType.index.getBookMarkType(),BMPIndexActivity
				 * .this)){ _messageHandler.post(new SaveMonitor(_item.length()
				 * >= 2 ? _item .substring(0, 2) :
				 * _item,MonitorUtil.items,BMPIndexActivity.this)); //} }
				 */
			new SaveBookMarkAsyncTask(_item,
					CommonDefn.BookMarkType.index.getBookMarkType(),
					BMPIndexActivity.this, MonitorUtil.getInstance(),
					_item.length() >= 2 ? _item.substring(0, 2) : _item)
					.execute();
/*			}
			catch (NotFoundException e)
			{
				e.printStackTrace();
			}
			finally
			{
				dbHelper.cleanup();
			}*/
		}
	}

	private void scrollToItemView()
	{
		final String itemCode = ((ITDLApplication) getApplicationContext())
				.getString(CommonDefn.FROM_MONITOR_TO_ACTIVITY_FORWARDING_ITEM);
		final String adapter = ((ITDLApplication) getApplicationContext())
				.getString(CommonDefn.FROM_MONITOR_TO_ACTIVITY_FORWARDING_ADAPTER);
		if (itemCode == null || itemCode.length() < 1 || adapter == null
				|| adapter.length() < 1)
		{
			return;
		}
		((ITDLApplication) getApplicationContext()).putString(
				CommonDefn.FROM_MONITOR_TO_ACTIVITY_FORWARDING_ITEM, null);
		((ITDLApplication) getApplicationContext()).putString(
				CommonDefn.FROM_MONITOR_TO_ACTIVITY_FORWARDING_ADAPTER,
				null);

		if (!ITEM_TO_TABINDEX.containsKey(itemCode + adapter)
				&& !ITEM_TO_TABINDEX.containsKey(itemCode))
		{
			return;
		}

		String key = itemCode + adapter;
		if (ITEM_TO_TABINDEX.containsKey(itemCode))
		{
			key = itemCode;
		}
		final int tabIndex = ITEM_TO_TABINDEX.get(key);
		// final ViewGroup tab = (ViewGroup) findViewById(R.id.mock_tab);
		// final Button tabBtn = (Button) tab.getChildAt(tabIndex);
		final Button tabBtn = _tabBtns[tabIndex];

		if (_messageHandler != null)
			_messageHandler.post(new Runnable()
			{
				public void run()
				{
					tabBtn.performClick();
				}
			});
	}

	private boolean isShouldShowImg(String itemCode)
	{
		boolean result = true;

		result = !noChartList.contains(itemCode);

		return result;

	}

	private class ForwardToChart implements OnClickListener
	{
		private String		_itemCode;
		private String		_itemName;
		private ViewGroup	_viewGroup;

		public ForwardToChart(String itemCode, String itemName,
				ViewGroup container)
		{
			_itemCode = itemCode;
			_itemName = itemName;
			_viewGroup = container;
		}

		@Override
		public void onClick(View v)
		{
			if (_itemName == null || _itemName.length() < 1)
			{
				View itemName = _viewGroup.findViewWithTag(NAME_TAG);
				if (itemName != null)
				{
					String strName = ((TextView) itemName).getText()
							.toString();
					TDStockLog.d(TAG, "name=" + strName + "=name");
					if (strName != null && strName.length() >= 1)
					{
						if (strName.contains("月期貨"))
						{
							strName = strName.replace("恆生指數", "恆指")
									.replace("國企指數", "國企")
									.replace("日經指數", "日經")
									.replace("道瓊斯", "道指")
									.replace("期貨", "");
						}
						forwardToNvChart(_itemCode,
								strName.replace("(延遲)", ""));
					}
				}
			}
			else
			{
				_itemName = _itemName.replace("<br>(延遲)", "");
			}
			// currentItemCode = _itemCode;
			forwardToNvChart(_itemCode, _itemName);
		}

	}

	private void forwardToNvChart(final String itemCode, final String itemName)
	{
		if (this.isShouldShowImg(itemCode))
		{

			Intent intent = new Intent(this, IndexChartActivity.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
					| Intent.FLAG_ACTIVITY_NO_USER_ACTION);
			if (itemName != null && itemName.length() > 0)
				((ITDLApplication) this.getApplicationContext())
						.setCurrentStockName(itemName); // only get part name on
													// all items
			intent.putExtra(FinalKey.ITEMCODE, itemCode);
			// startActivityForResult(intent, Activity.RESULT_OK);
			// startActivity(intent);
			SwitchActivityFromHost(IndexChartActivity.class, intent);
		}
	}

	// @Override
	protected boolean forwardToChartActivity()
	{
		if (_chartImg != null)
		{
			String currentItemCode = _chartImg.getTag(CHART_IMG_TAG_FOR_KEY)
					.toString();

			OnClickListener clicking = (OnClickListener) _chartImg
					.getTag(CHART_IMG_TAG_FOR_CLICK);
			if (currentItemCode == null)
			{

				TDStockLog.d(TAG, "itemCode is null");

				TDStockLog.d(TAG, "not forwardTo chart");

				return false;
			}

			if (this.isShouldShowImg(currentItemCode))
			{
				if (_chartImg != null)
				{
					// _chartImg.performClick();
					if (clicking != null)
					{
						clicking.onClick(_chartImg);
					}

					TDStockLog.d(TAG, "forwardTo chart -> itemCode:"
							+ currentItemCode);
					return true;
				}
			}
		}

		TDStockLog.d(TAG, "not forwardTo chart");
		return false;
	}

	private void initHasChartList()
	{
		String[] shouldHideItems = { INDEX_TELETEXT_ALL_ITEMS[2],
				INDEX_TELETEXT_ALL_ITEMS[3], INDEX_TELETEXT_ALL_ITEMS[4],
				INDEX_TELETEXT_ALL_ITEMS[5], INDEX_TELETEXT_ALL_ITEMS[6],
				INDEX_TELETEXT_ALL_ITEMS[7],

				WORLD_INDEX_ITEMS_DELAY_AND_REALTIME[1],
				WORLD_INDEX_ITEMS_DELAY_AND_REALTIME[3],
				WORLD_INDEX_ITEMS_DELAY_AND_REALTIME[4],

				WORLD_INDEX_ITEMS[5], WORLD_INDEX_ITEMS[6],
				WORLD_INDEX_ITEMS[7], WORLD_INDEX_ITEMS[8],
				WORLD_INDEX_ITEMS[9], WORLD_INDEX_ITEMS[10],
				WORLD_INDEX_ITEMS[11], WORLD_INDEX_ITEMS[12],
				WORLD_INDEX_ITEMS[13], /* WORLD_INDEX_ITEMS[14], */

				WORLD_INDEX_ITEMS[16 - 1], WORLD_INDEX_ITEMS[17 - 1],
				WORLD_INDEX_ITEMS[19 - 1],/* 隐藏印度SEN index=10 */

				WORLD_INDEX_DELAY_ITEMS[0], WORLD_INDEX_DELAY_ITEMS[1], };

		for (String temp : shouldHideItems)
		{

			noChartList.add(temp);
		}
	}

	private void changeIndexNameTextForDelayData(ViewGroup container)
	{
		TextView index_name = ((TextView) container.findViewWithTag(NAME_TAG));

		if (TAB4And5Map.containsKey(container.getId()))
		{
			if (((ITDLApplication) getApplicationContext()).getDataMode() == DataMode.Delay)
			{
				if (index_name.getText().toString().indexOf("延遲") != -1)
				{
					String name = index_name.getText().toString();
					index_name.setText(Html.fromHtml(name.substring(0,
							name.length() - "(延遲)".length())));
				}
				index_name.setTextColor(Color.WHITE);
			}
			else
			{
				index_name.setTextColor(Color.YELLOW);
			}
		}
		else if (TAB1And2Map.containsKey(container.getId())) // "期指(Futures)"
		{
			// account login 未購買 "期指(Futures)"
			if (!((ITDLApplication) getApplicationContext())
					.getIsRealtimeFutures())
			{
				index_name.setTextColor(Color.YELLOW);
			}
			else
			{
				index_name.setTextColor(Color.WHITE);
			}
		}
		else if (TAB1And3Map.containsKey(container.getId()))// "上証(SSEI)"
		{
			// account login 未購買 "上証(SSEI)"
			if (!((ITDLApplication) getApplicationContext())
					.getIsRealtimeSSEI())
			{
				index_name.setTextColor(Color.YELLOW);
			}
			else
			{
				if (index_name.getText().toString().indexOf("延遲") != -1)
				{
					String name = index_name.getText().toString();
					index_name.setText(Html.fromHtml(name.substring(0,
							name.length() - "(延遲)".length())));
				}
				index_name.setTextColor(Color.WHITE);
			}
		}
	}

	@Override
	protected void onResume()
	{
		super.SetExectuHttpRequestOnResume(false);
		super.onResume();
		TDStockLog.d(TAG, TAG + " onResume");

		if (isChangeModeType)
		{
			// "期指Futures"，"上証SSEI" set Adapter
			// initFuturesAndSSEIAdapterType();
			initIndexViews();
			isChangeModeType = false;
		}

		{
			final Runnable myUpdateResults = new Runnable()
			{
				public void run()
				{
					scrollToItemView();
				}
			};

			new Thread()
			{
				public void run()
				{
					if (_messageHandler != null)
					{
						_messageHandler.post(myUpdateResults);
					}

				}
			}.start();
		}

		loadDataUpdateUI(_tabIndex); // get data update ui
	}

	@Override
	protected void onPause()
	{
		super.onPause();
		TDStockLog.d(TAG, TAG + " onPause");
		// if(indexAsyncTask != null)
		// {
		// indexAsyncTask.cancel(true);
		// indexAsyncTask = null;
		// }
	}

	@Override
	protected void onStart()
	{
		super.onStart();
		TDStockLog.d(TAG, TAG + " onStart");
	}

	@Override
	protected void onRestart()
	{
		super.onRestart();
		TDStockLog.d(TAG, TAG + " onRestart");
	}

	@Override
	protected void onStop()
	{
		super.onStop();
		TDStockLog.d(TAG, TAG + " onStop");
	}

	@Override
	protected void onDestroy()
	{
		super.onDestroy();
		TDStockLog.d(TAG, TAG + " onDestroy");
	}

	@Override
	public void onBackPressed()
	{
		super.onBackPressed();
		TDStockLog.d(TAG, TAG + " onBackPressed");
	}

	@Override
	public ActivityGroupController GetActivityGroupController()
	{
		return IndexGroup.GetActivityGroupHostControl();
	}

	@Override
	public void ScreenOrientation_Response(SCR_ORIENTATION orientation)
	{
		if ((orientation == SCR_ORIENTATION.LANDSCAPE))
		{
			forwardToChartActivity();
		}
	}

	private void loadDataUpdateUI(int tabIndex, String... isSunflower)
	{
		// if(indexAsyncTask == null)
		// {
		// // Toast.makeText(getMyOwnContext(), TAG + " Update Data",
		// Toast.LENGTH_SHORT).show();
		// indexAsyncTask = new IndexAsyncTask(getMyOwnContext(),
		// isSunflower.length <= 0);
		// indexAsyncTask.execute(String.valueOf(tabIndex));
		// }

		if (isSunflower.length <= 0)
			SetShowProgressView(true);
		else
			SetShowProgressView(false);

		SendHttpRequest();
	}

	private void OnUpdateWorldFutures(final int itemPos,
			final String itemName, final WorldFutures update, final int tab)
	{
		final Runnable myUpdateResults = new Runnable()
		{
			public void run()
			{
				String mm = update.getMm();
				String last = update.getLast();
				String net = update.getNet();
				String high = update.getHigh();
				String low = update.getLow();
				String open = update.getOpen();

				if (last == null || net == null)
				{
					return;
				}

				net = StringUtils.formatToEitherDp(net, -10.0, 10.0, 2, 0);

				boolean isNegative = net.indexOf("-") >= 0;

				// for (int tab = 0; tab < 2; tab++)
				// {
				TextView[] holder = _index_futures_views[tab][itemPos];

				{
					Message exMessage;
					TextView currentView;

					currentView = holder[0];
					exMessage = UIUpdater.obtainMessage();
					exMessage.what = INFO_CONTENT_UPDATE;
					exMessage.obj = new DoThingsReturn(last == null ? ""
							: StringUtils.formatScaleInteger(Double
									.parseDouble(last)), currentView,
							0);
					exMessage.arg1 = 1;
					UIUpdater.sendMessage(exMessage);

					ViewGroup container = (ViewGroup) currentView
							.getParent().getParent(); // two level

					TextView index_name = ((TextView) container
							.findViewWithTag(NAME_TAG));
					index_name.setText(index_name
							.getText()
							.toString()
							.replace("--",
									String.valueOf(Integer
											.parseInt(mm))));
				}
				{
					try
					{
						if (last != null)
							holder[0].setText(StringUtils
									.formatScaleInteger(Double
											.parseDouble(last)));

						ViewGroup container = (ViewGroup) holder[0]
								.getParent().getParent(); // two level
						TextView index_name = ((TextView) container
								.findViewWithTag(NAME_TAG));
						index_name.setText(index_name
								.getText()
								.toString()
								.replace("--",
										String.valueOf(Integer
												.parseInt(mm))));
					}
					catch (Exception e)
					{
						e.printStackTrace();
					}
				}
				{
					TextView currentView = holder[1];
					try
					{
						currentView.setText(StringUtils.formatString(net,
								isNegative ? null : "+", null));
						currentView.setTextColor(isNegative ? Color.RED
								: Color.GREEN);
					}
					catch (Exception e)
					{
						e.printStackTrace();
					}
				}
				{
					holder[2].setText("");
				}
				{
					try
					{
						if (high != null)
							holder[3].setText(StringUtils
									.formatScaleInteger(Double
											.parseDouble(high)));
					}
					catch (Exception e)
					{
						e.printStackTrace();
					}
				}
				{
					try
					{
						if (low != null)
							holder[4].setText(StringUtils
									.formatScaleInteger(Double
											.parseDouble(low)));
					}
					catch (Exception e)
					{
						e.printStackTrace();
					}
				}
				{
					try
					{
						if (open != null)
							holder[5].setText(StringUtils
									.formatScaleInteger(Double
											.parseDouble(open)));
					}
					catch (Exception e)
					{
						e.printStackTrace();
					}
				}
				// }
			}
		};

		new Thread()
		{
			public void run()
			{
				if (_messageHandler != null)
					_messageHandler.post(myUpdateResults);
			}
		}.start();
	}

	private void OnUpdateWorldIndexOther(final int itemPos,
			final String itemName, final WorldIndex update)
	{
		final Runnable myUpdateResults = new Runnable()
		{
			public void run()
			{
				String last = update.getLast();
				String net = update.getNet();
				// String net_percentage = update.getNetPercentage();
				String high = update.getHigh();
				String low = update.getLow();
				String open = update.getOpen();
				String prev = update.getPrev();

				if (last == null || net == null)
				{
					return;
				}

				String net_percentage = StringUtils
						.formatRoundUpByNetPercetageNumber(Double
								.parseDouble(net)
								/ Double.parseDouble(prev) * 100);

				net = StringUtils.formatToEitherDp(net, -10.0, 10.0, 2, 0);

				boolean isNegative = net.indexOf("-") >= 0;

				TextView[] holder = null;
				if (itemPos <= 20)
				{
					holder = _world_index_views[itemPos];
				}
				else
				{
					holder = _worldIndex_delay[itemPos - 50];
				}

				{
					Message exMessage;
					TextView currentView;

					currentView = holder[0];

					exMessage = UIUpdater.obtainMessage();
					exMessage.what = INFO_CONTENT_UPDATE;
					exMessage.obj = new DoThingsReturn(last == null ? ""
							: StringUtils.formatScaleInteger(Double
									.parseDouble(last)), currentView,
							0);
					exMessage.arg1 = 1;
					UIUpdater.sendMessage(exMessage);
				}

				{
					if (last != null)
						holder[0].setText(StringUtils
								.formatScaleInteger(Double
										.parseDouble(last)));
				}
				{
					TextView currentView = holder[1];
					try
					{
						currentView.setText(StringUtils.formatString(net,
								isNegative ? null : "+", null));
						currentView.setTextColor(isNegative ? Color.RED
								: Color.GREEN);
					}
					catch (Exception e)
					{
						e.printStackTrace();
					}
				}
				{
					TextView currentView = holder[2];
					try
					{
						net_percentage = StringUtils
								.formatToFiveCharsRule(net_percentage)
								+ "%";
						net_percentage = StringUtils.formatString(
								net_percentage,
								isNegative ? null : "+", null);
						currentView.setText(net_percentage);
						currentView.setTextColor(isNegative ? Color.RED
								: Color.GREEN);
					}
					catch (Exception e)
					{
						e.printStackTrace();
					}
				}
				{
					try
					{
						if (high != null)
							holder[3].setText(StringUtils
									.formatScaleInteger(Double
											.parseDouble(high)));
					}
					catch (Exception e)
					{
						e.printStackTrace();
					}
				}
				{
					try
					{
						if (low != null)
							holder[4].setText(StringUtils
									.formatScaleInteger(Double
											.parseDouble(low)));
					}
					catch (Exception e)
					{
						e.printStackTrace();
					}
				}
				{
					try
					{
						if (open != null)
							holder[5].setText(StringUtils
									.formatScaleInteger(Double
											.parseDouble(open)));
					}
					catch (Exception e)
					{
						e.printStackTrace();
					}
				}
				{
					try
					{
						if (prev != null)
							holder[6].setText(StringUtils
									.formatScaleInteger(Double
											.parseDouble(prev)));
					}
					catch (Exception e)
					{
						e.printStackTrace();
					}
				}
			}
		};

		new Thread()
		{
			public void run()
			{
				_messageHandler.post(myUpdateResults);
			}
		}.start();
	}

	private void OnUpdateWorldIndexSSEI(final int itemPos,
			final String itemName, final WorldIndex update)
	{
		final Runnable myUpdateResults = new Runnable()
		{
			public void run()
			{
				String last = update.getLast();
				String net = update.getNet();
				// String net_percentage = update.getNetPercentage();
				String high = update.getHigh();
				String low = update.getLow();
				String open = update.getOpen();
				String prev = update.getPrev();
				String vol = update.getVol();

				if (last == null || net == null)
				{
					return;
				}
				String net_percentage = StringUtils
						.formatRoundUpByNetPercetageNumber(Double
								.parseDouble(net)
								/ Double.parseDouble(prev) * 100);
				net = StringUtils.formatToEitherDp(net, -10.0, 10.0, 2, 0);

				boolean isNegative = net.indexOf("-") >= 0;

				TextView[] holder = _world_index_delay_realtime_views[itemPos];

				{
					Message exMessage;
					TextView currentView;

					currentView = holder[0];

					exMessage = UIUpdater.obtainMessage();
					exMessage.what = INFO_CONTENT_UPDATE;
					exMessage.obj = new DoThingsReturn(last == null ? ""
							: StringUtils.formatScaleInteger(Double
									.parseDouble(last)), currentView,
							0);
					exMessage.arg1 = 1;
					UIUpdater.sendMessage(exMessage);
				}

				{
					if (last != null)
						holder[0].setText(StringUtils
								.formatScaleInteger(Double
										.parseDouble(last)));
				}
				{
					TextView currentView = holder[1];
					try
					{
						currentView.setText(StringUtils.formatString(net,
								isNegative ? null : "+", null));
						currentView.setTextColor(isNegative ? Color.RED
								: Color.GREEN);
					}
					catch (Exception e)
					{
						e.printStackTrace();
					}
				}
				{
					TextView currentView = holder[2];
					try
					{
						net_percentage = StringUtils
								.formatToFiveCharsRule(net_percentage)
								+ "%";
						net_percentage = StringUtils.formatString(
								net_percentage,
								isNegative ? null : "+", null);
						currentView.setText(net_percentage);
						currentView.setTextColor(isNegative ? Color.RED
								: Color.GREEN);
					}
					catch (Exception e)
					{
						e.printStackTrace();
					}
				}
				{
					try
					{
						if (high != null)
							holder[3].setText(StringUtils
									.formatScaleInteger(Double
											.parseDouble(high)));
					}
					catch (Exception e)
					{
						e.printStackTrace();
					}
				}
				{
					try
					{
						if (low != null)
							holder[4].setText(StringUtils
									.formatScaleInteger(Double
											.parseDouble(low)));
					}
					catch (Exception e)
					{
						e.printStackTrace();
					}
				}
				{
					try
					{
						if (open != null)
							holder[5].setText(StringUtils
									.formatScaleInteger(Double
											.parseDouble(open)));
					}
					catch (Exception e)
					{
						e.printStackTrace();
					}
				}

				if (itemPos != 0)
				{
					try
					{
						if (prev != null)
							holder[6].setText(StringUtils
									.formatScaleInteger(Double
											.parseDouble(prev)));
					}
					catch (Exception e)
					{
						e.printStackTrace();
					}
				}
				else
				{
					try
					{
						((TextView) findViewById(R.id.index_preset_sse)
								.findViewWithTag(REPLACEMENT_TAG))
								.setText(R.string.index_sharetraded);
						holder[6].setText(/*
										 * _formater.format(Double.parseDouble(vol
										 * ) / 100000000.00d)
										 */StringUtils.roundDownInteger(String
								.valueOf(Double.parseDouble(vol) / 100000000.00d))
								+ getResources().getString(
										R.string.a_hundred_million));
					}
					catch (NumberFormatException e)
					{
						e.printStackTrace();
					}
					catch (Exception e)
					{
						e.printStackTrace();
					}
				}
			}
		};

		new Thread()
		{
			public void run()
			{
				_messageHandler.post(myUpdateResults);
			}
		}.start();
	}

	private void OnUpdateFutures(final int itemPos, final String itemName,
			final Futures update, final int tab)
	{
		final Runnable myUpdateResults = new Runnable()
		{
			public void run()
			{
				String mm = update.getMm();
				String last = update.getLast();
				String net = update.getNet();
				String prev = update.getPrev();
				String high = update.getHigh();
				String low = update.getLow();
				String open = update.getOpen();
				String vol = update.getVol();

				if (last == null || net == null)
				{
					return;
				}

				String label_name = "";
				if (mm != null && itemPos >= 0
						&& itemPos < INDEX_FUTURES_LABEL_IDS.length)
				{
					label_name = getResources().getString(
							INDEX_FUTURES_LABEL_IDS[itemPos],
							Integer.parseInt(mm));
				}
				String netPrecentage = null;
				if (prev != null && net != null)
				{
					netPrecentage = StringUtils
							.formatRoundUpByNetPercetageNumber(Double
									.parseDouble(net)
									/ Double.parseDouble(prev) * 100);
				}
				net = StringUtils.formatToEitherDp(net, -10.0, 10.0, 2, 0);

				boolean isNegative = net.indexOf("-") >= 0;

				// for (int tab = 0; tab < 2; tab++)
				// {
				TextView[] holder = _index_futures_views[tab][itemPos];

				{
					Message exMessage;
					TextView currentView;

					currentView = holder[0];
					exMessage = UIUpdater.obtainMessage();
					exMessage.what = INFO_CONTENT_UPDATE;
					exMessage.obj = new DoThingsReturn(last == null ? ""
							: StringUtils.formatScaleInteger(Double
									.parseDouble(last)), currentView,
							0);
					exMessage.arg1 = 1;
					UIUpdater.sendMessage(exMessage);
					ViewGroup container = (ViewGroup) currentView
							.getParent().getParent(); // two level
					((TextView) container.findViewWithTag(NAME_TAG))
							.setText(Html.fromHtml(label_name));
				}
				{
					try
					{
						if (last != null)
							holder[0].setText(StringUtils
									.formatScaleInteger(Double
											.parseDouble(last)));

						ViewGroup container = (ViewGroup) holder[0]
								.getParent().getParent(); // two level
						((TextView) container.findViewWithTag(NAME_TAG))
								.setText(Html.fromHtml(label_name));
					}
					catch (Exception e)
					{
						e.printStackTrace();
					}
				}
				{
					TextView currentView = holder[1];
					try
					{
						currentView.setText(StringUtils.formatString(net,
								isNegative ? null : "+", null));
						currentView.setTextColor(isNegative ? Color.RED
								: Color.GREEN);
					}
					catch (Exception e)
					{
						e.printStackTrace();
					}
				}
				{
					TextView currentView = holder[2];
					try
					{
						if (netPrecentage != null
								&& !netPrecentage.endsWith("%"))
						{
							netPrecentage = StringUtils
									.formatNumberByNetPerectage(
											netPrecentage, 4);
						}
						else
						{
							netPrecentage = CommonDefn.DEFAULT_FIELD_VALUE;
						}
						currentView.setText(netPrecentage);
						currentView.setTextColor(isNegative ? Color.RED
								: Color.GREEN);
					}
					catch (Exception e)
					{
						e.printStackTrace();
					}
				}
				{
					try
					{
						if (high != null)
							holder[3].setText(StringUtils
									.formatScaleInteger(Double
											.parseDouble(high)));
					}
					catch (Exception e)
					{
						e.printStackTrace();
					}
				}
				{
					try
					{
						if (low != null)
							holder[4].setText(StringUtils
									.formatScaleInteger(Double
											.parseDouble(low)));
					}
					catch (Exception e)
					{
						e.printStackTrace();
					}
				}
				{
					try
					{
						if (open != null)
							holder[5].setText(StringUtils
									.formatScaleInteger(Double
											.parseDouble(open)));
					}
					catch (Exception e)
					{
						e.printStackTrace();
					}
				}
				{
					try
					{
						if (vol != null)
							holder[6].setText(StringUtils
									.formatScaleInteger(Double
											.parseDouble(vol)));
					}
					catch (Exception e)
					{
						e.printStackTrace();
					}
				}
				// } //end the loop
			}
		};

		new Thread()
		{
			public void run()
			{
				_messageHandler.post(myUpdateResults);
			}
		}.start();
	}

	public void OnUpdateIndex(final int itemPos, final String itemName,
			final Index update, final int index)
	{
		final Runnable myUpdateResults = new Runnable()
		{
			public void run()
			{
				String last = update.getLast();
				String net = update.getNet();
				// String netPrecentage = update.getNetPercentage();
				String high = update.getHigh();
				String low = update.getLow();
				String open = update.getOpen();
				String prev = update.getPrev();
				String turnover = update.getVol();

				if (high == null)
				{
					high = "0.00";
				}
				if (low == null)
				{
					low = "0.00";
				}
				if (open == null)
				{
					open = "0.00";
				}
				if (prev == null)
				{
					prev = "0.00";
				}
				if (turnover == null)
				{
					turnover = "0.00";
				}
				String netPrecentage = StringUtils
						.formatRoundUpByNetPercetageNumber(Double
								.parseDouble(net)
								/ Double.parseDouble(prev) * 100);
				net = StringUtils.formatToEitherDp(net, -10.0, 10.0, 2, 0);

				boolean isNegative = net.indexOf("-") >= 0;
				if (itemPos == 0 || itemPos == 1)
				{
					// for (int index = 0; index < 2; index++)
					// {
					{
						Message exMessage;
						TextView currentView;

						currentView = itemName.equals(INDEX_NAME_HSI) ? _index_hsi_views[index][0]
								: _index_hscei_views[index][0];

						exMessage = UIUpdater.obtainMessage();
						exMessage.what = INFO_CONTENT_UPDATE;
						exMessage.obj = new DoThingsReturn(
								last == null ? "" : StringUtils
										.formatScaleInteger(Double
												.parseDouble(last)),
								currentView, 0);
						exMessage.arg1 = 1;
						UIUpdater.sendMessage(exMessage);
					}
					{
						TextView currentView = itemName
								.equals(INDEX_NAME_HSI) ? _index_hsi_views[index][0]
								: _index_hscei_views[index][0];
						currentView.setText(last == null ? ""
								: StringUtils.formatScaleInteger(Double
										.parseDouble(last)));
					}
					{
						try
						{
							TextView currentView = itemName
									.equals(INDEX_NAME_HSI) ? _index_hsi_views[index][1]
									: _index_hscei_views[index][1];
							currentView.setText(StringUtils
									.formatString(net,
											isNegative ? null : "+",
											null));
							currentView
									.setTextColor(isNegative ? Color.RED
											: Color.GREEN);
						}
						catch (Exception e)
						{
							e.printStackTrace();
						}
					}
					{
						try
						{
							TextView currentView = itemName
									.equals(INDEX_NAME_HSI) ? _index_hsi_views[index][2]
									: _index_hscei_views[index][2];
							if (!netPrecentage.contains("%"))
								netPrecentage = StringUtils
										.formatNumberByNetPerectage(
												netPrecentage, 4);
							currentView.setText(netPrecentage);
							currentView
									.setTextColor(isNegative ? Color.RED
											: Color.GREEN);
						}
						catch (Exception e)
						{
							e.printStackTrace();
						}
					}
					{
						try
						{
							TextView currentView = itemName
									.equals(INDEX_NAME_HSI) ? _index_hsi_views[index][3]
									: _index_hscei_views[index][3];
							if (high != null)
								currentView
										.setText(StringUtils
												.formatScaleInteger(Double
														.parseDouble(high)));
						}
						catch (Exception e)
						{
							e.printStackTrace();
						}
					}
					{
						try
						{
							TextView currentView = itemName
									.equals(INDEX_NAME_HSI) ? _index_hsi_views[index][4]
									: _index_hscei_views[index][4];
							if (low != null)
								currentView.setText(StringUtils
										.formatScaleInteger(Double
												.parseDouble(low)));
						}
						catch (Exception e)
						{
							e.printStackTrace();
						}
					}
					{
						try
						{
							TextView currentView = itemName
									.equals(INDEX_NAME_HSI) ? _index_hsi_views[index][5]
									: _index_hscei_views[index][5];
							if (open != null)
								currentView
										.setText(StringUtils
												.formatScaleInteger(Double
														.parseDouble(open)));
						}
						catch (Exception e)
						{
							e.printStackTrace();
						}
					}
					if (itemName.equals(INDEX_NAME_HSI))
					{
						try
						{
							_index_hsi_views[index][6]
									.setText(/*
											 * _formater.format(Double.parseDouble
											 * (turnover) / 100000000.00d)
											 */StringUtils.roundDownInteger(String.valueOf(Double
											.parseDouble(turnover) / 100000000.00d))
											+ getResources()
													.getString(
															R.string.a_hundred_million));
							TDStockLog.i(
									TAG,
									"HG-- "
											+ /*
												* _formater .format(Double
												* .parseDouble(turnover) /
												* 100000.00d)
												*/StringUtils
													.roundDownInteger(String
															.valueOf(Double
																	.parseDouble(turnover) / 100000000.00d))
											+ getResources()
													.getString(
															R.string.a_hundred_million));
						}
						catch (NumberFormatException e)
						{
							e.printStackTrace();
						}
						catch (NotFoundException e)
						{
							e.printStackTrace();
						}
					}
					else if (itemName.equals(INDEX_NAME_HSCEI))
					{
						try
						{
							if (prev != null)
								_index_hscei_views[index][6]
										.setText(StringUtils
												.formatScaleInteger(Double
														.parseDouble(prev)));
						}
						catch (Exception e)
						{
							e.printStackTrace();
						}
					}
					// }
				}
				else
				{
					{
						try
						{
							TextView currentView = _index_category[itemPos - 2][0];
							if (last != null)
								currentView
										.setText(StringUtils
												.formatScaleInteger(Double
														.parseDouble(last)));
						}
						catch (Exception e)
						{
							e.printStackTrace();
						}
					}
					{
						try
						{
							TextView currentView = _index_category[itemPos - 2][1];
							currentView.setText(StringUtils
									.formatString(net,
											isNegative ? null : "+",
											null));
							currentView
									.setTextColor(isNegative ? Color.RED
											: Color.GREEN);
						}
						catch (Exception e)
						{
							e.printStackTrace();
						}
					}
					{
						try
						{
							TextView currentView = _index_category[itemPos - 2][2];
							if (!netPrecentage.contains("%"))
								netPrecentage = StringUtils
										.formatNumberByNetPerectage(
												netPrecentage, 4);
							currentView.setText(netPrecentage);
							currentView
									.setTextColor(isNegative ? Color.RED
											: Color.GREEN);
						}
						catch (Exception e)
						{
							e.printStackTrace();
						}
					}
					{
						try
						{
							if (high != null)
								_index_category[itemPos - 2][3]
										.setText(StringUtils
												.formatScaleInteger(Double
														.parseDouble(high)));
						}
						catch (Exception e)
						{
							e.printStackTrace();
						}
					}
					{
						try
						{
							if (low != null)
								_index_category[itemPos - 2][4]
										.setText(StringUtils
												.formatScaleInteger(Double
														.parseDouble(low)));
						}
						catch (Exception e)
						{
							e.printStackTrace();
						}
					}
					{
						try
						{
							if (open != null)
								_index_category[itemPos - 2][5]
										.setText(StringUtils
												.formatScaleInteger(Double
														.parseDouble(open)));
						}
						catch (Exception e)
						{
							e.printStackTrace();
						}
					}
					{
						try
						{
							if (prev != null)
								_index_category[itemPos - 2][6]
										.setText(StringUtils
												.formatScaleInteger(Double
														.parseDouble(prev)));
						}
						catch (Exception e)
						{
							e.printStackTrace();
						}
					}
				}
			}
		};

		new Thread()
		{
			public void run()
			{
				_messageHandler.post(myUpdateResults);
			}
		}.start();
	}

	// private class IndexAsyncTask extends BaseAsyncTask
	// {
	// private boolean isSunflower = true;
	//
	// public IndexAsyncTask(Context context)
	// {
	// super(context);
	// }
	//
	// public IndexAsyncTask(Context context, boolean isbool)
	// {
	// super(context);
	// this.isSunflower = isbool;
	// }
	//
	// @Override
	// protected void onPreExecute()
	// {
	// if(isSunflower)
	// super.onPreExecute();
	// }
	//
	// @Override
	// protected Void doInBackground(String... params)
	// {
	// int tabIndex = Integer.parseInt(params[0]);
	//
	// // Index
	// /*
	// * tab 0: TypeName[0~1]
	// * tab 1: TypeName all
	// */
	// String itemCodeList_index = null;
	// if(tabIndex == 0)
	// {
	// itemCodeList_index = Index.TypeName_Str_Tab0;
	// // itemCodeList_index = new String[] { Index.TypeName[0],
	// Index.TypeName[1] };
	// }
	// else if(tabIndex == 1)
	// {
	// itemCodeList_index = Index.TypeName_Str_Tab1;
	// // itemCodeList_index = Index.TypeName;
	// }
	//
	// if(itemCodeList_index != null)
	// {
	// Map<String, Index> indexList =
	// HttpDataBaseUtils.getDataByIndex2(itemCodeList_index,
	// ((ITDLApplication)getApplicationContext()).getSessionAccount(),
	// ((ITDLApplication)getApplicationContext()).getSessionToken());
	// // List<Index> indexList =
	// HttpDataBaseUtils.getDataByIndex(itemCodeList_index);
	// for(int i = 0; i < indexList.size(); i++)
	// {
	// try
	// {
	// Index index = indexList.get(Index.TypeName[i]);
	// OnUpdateIndex(i, index.getName(), index, tabIndex);
	// }
	// catch(Exception e)
	// {
	// TDStockLog.d(TAG, "exception=Index foreach=" + Index.TypeName[i] + " > "
	// + e.toString());
	// }
	// }
	// }
	//
	// // Futures
	// /*
	// * tab 0: TypeName all
	// * tab 1: TypeName all
	// */
	// if(tabIndex == 0 || tabIndex == 1)
	// {
	// Map<String, Futures> futuresList =
	// HttpDataBaseUtils.getDataByFutures2(!((ITDLApplication)getApplicationContext()).getIsRealtimeFutures(),
	// ((ITDLApplication)getApplicationContext()).getSessionAccount(),
	// ((ITDLApplication)getApplicationContext()).getSessionToken());
	// // List<Futures> futuresList =
	// HttpDataBaseUtils.getDataByFutures(((ITDLApplication)getApplicationContext()).getIsRealtimeFutures());
	// for(int i = 0; i < Futures.TypeName.length; i++)
	// {
	// try
	// {
	// Futures futures = futuresList.get(Futures.TypeName[i]);
	// OnUpdateFutures(i, futures.getName(), futures, tabIndex);
	// }
	// catch(Exception e)
	// {
	// TDStockLog.d(TAG, "exception=Futures foreach=" + Futures.TypeName[i] +
	// " > " + e.toString());
	// continue;
	// }
	// }
	// }
	//
	// // WorldIndex SSEI
	// /*
	// * tab 0: TypeName[0]
	// * tab 2: TypeName all
	// */
	// String itemCodeList_worldIndex_ssei = null;
	// if(tabIndex == 0)
	// {
	// itemCodeList_worldIndex_ssei = WorldIndex.TypeName_SSEI_Str_Tab0;
	// // itemCodeList_worldIndex_ssei = new String[] {
	// WorldIndex.TypeName_SSEI[0] };
	// }
	// else if(tabIndex == 2)
	// {
	// itemCodeList_worldIndex_ssei = WorldIndex.TypeName_SSEI_Str_Tab2;
	// // itemCodeList_worldIndex_ssei = WorldIndex.TypeName_SSEI;
	// }
	//
	// if(itemCodeList_worldIndex_ssei != null)
	// {
	// Map<String, WorldIndex> worldIndexSSEIList =
	// HttpDataBaseUtils.getDataByWorldIndexSSEI2(!((ITDLApplication)getApplicationContext()).getIsRealtimeSSEI(),
	// itemCodeList_worldIndex_ssei,
	// ((ITDLApplication)getApplicationContext()).getSessionAccount(),
	// ((ITDLApplication)getApplicationContext()).getSessionToken());
	// // List<WorldIndex> worldIndexSSEIList =
	// HttpDataBaseUtils.getDataByWorldIndexSSEI(((ITDLApplication)getApplicationContext()).getIsRealtimeSSEI(),
	// itemCodeList_worldIndex_ssei);
	// for(int i = 0; i < WorldIndex.TypeName_SSEI.length; i++)
	// {
	// try
	// {
	// WorldIndex worldIndex =
	// worldIndexSSEIList.get(WorldIndex.TypeName_SSEI[i]);
	// if(tabIndex == 0)
	// {
	// OnUpdateWorldIndexSSEI(0, worldIndex.getName(), worldIndex);
	// }
	// else
	// {
	// if(i == 0)
	// {
	// OnUpdateWorldIndexSSEI(2, worldIndex.getName(), worldIndex);
	// }
	// else if(i == 1)
	// {
	// OnUpdateWorldIndexSSEI(i, worldIndex.getName(), worldIndex);
	// }
	// else if(i >= 2)
	// {
	// OnUpdateWorldIndexSSEI(i + 1, worldIndex.getName(), worldIndex);
	// }
	// }
	// }
	// catch(Exception e)
	// {
	// TDStockLog.d(TAG, "exception=WorldIndex SSEI foreach=" +
	// WorldIndex.TypeName_SSEI[i] + " > " + e.toString());
	// continue;
	// }
	// }
	// }
	//
	// // WorldIndex Other
	// /*
	// * tab 0: TypeName[0~3]
	// * tab 2: TypeName[17~18]
	// * tab 3: TypeName[0], TypeName[4~13]
	// * tab 4: TypeName[1~3], TypeName[14~16]
	// */
	// String itemCodeList_worldIndex_other_str = null;
	// String[] itemCodeList_worldIndex_other = null;
	// if(tabIndex == 0)
	// {
	// itemCodeList_worldIndex_other_str = WorldIndex.TypeName_Other_Str_Tab0;
	// itemCodeList_worldIndex_other = new String[] {
	// WorldIndex.TypeName_Other[0], WorldIndex.TypeName_Other[1],
	// WorldIndex.TypeName_Other[2], WorldIndex.TypeName_Other[3] };
	// }
	// else if(tabIndex == 2)/*隐藏印度SEN index=10*/
	// {
	// itemCodeList_worldIndex_other_str = WorldIndex.TypeName_Other_Str_Tab2;
	// itemCodeList_worldIndex_other = new String[] {
	// WorldIndex.TypeName_Other[17-1], WorldIndex.TypeName_Other[18-1] };
	// }
	// else if(tabIndex == 3)/*隐藏印度SEN index=10*/
	// {
	// itemCodeList_worldIndex_other_str = WorldIndex.TypeName_Other_Str_Tab3;
	// itemCodeList_worldIndex_other = new String[] {
	// WorldIndex.TypeName_Other[0], WorldIndex.TypeName_Other[4],
	// WorldIndex.TypeName_Other[5],
	// WorldIndex.TypeName_Other[6], WorldIndex.TypeName_Other[7],
	// WorldIndex.TypeName_Other[8], WorldIndex.TypeName_Other[9],
	// WorldIndex.TypeName_Other[10], WorldIndex.TypeName_Other[11],
	// WorldIndex.TypeName_Other[12]/*, WorldIndex.TypeName_Other[13]*/ };
	// }
	// else if(tabIndex == 4)/*隐藏印度SEN index=10*/
	// {
	// itemCodeList_worldIndex_other_str = WorldIndex.TypeName_Other_Str_Tab4;
	// itemCodeList_worldIndex_other = new String[] {
	// WorldIndex.TypeName_Other[1], WorldIndex.TypeName_Other[2],
	// WorldIndex.TypeName_Other[3],
	// WorldIndex.TypeName_Other[14-1], WorldIndex.TypeName_Other[15-1],
	// WorldIndex.TypeName_Other[16-1] };
	// }
	//
	// if(itemCodeList_worldIndex_other != null)
	// {
	// Map<String, WorldIndex> worldIndexList =
	// HttpDataBaseUtils.getDataByWorldIndexOther2(itemCodeList_worldIndex_other_str,
	// ((ITDLApplication)getApplicationContext()).getSessionAccount(),
	// ((ITDLApplication)getApplicationContext()).getSessionToken());
	// // List<WorldIndex> worldIndexList =
	// HttpDataBaseUtils.getDataByWorldIndexOther(itemCodeList_worldIndex_other);
	// for(int i = 0; i < itemCodeList_worldIndex_other.length; i++)
	// {
	// try
	// {
	// WorldIndex worldIndex =
	// worldIndexList.get(itemCodeList_worldIndex_other[i]);
	//
	// if(worldIndex == null) continue;
	//
	// if(tabIndex == 0)
	// {
	// OnUpdateWorldIndexOther(i, worldIndex.getName(), worldIndex);
	// }
	// else if(tabIndex == 2)
	// {
	// // 深圳SZA，深圳SZB
	// OnUpdateWorldIndexOther(i + 50, worldIndex.getName(), worldIndex);
	// }
	// else if(tabIndex == 3) /*隐藏印度SEN index=10*/
	// {
	// TDStockLog.d(TAG,
	// "tabIndex="+tabIndex+" , index="+(i+4)+" , "+worldIndex.getName());
	// OnUpdateWorldIndexOther(i + 4, worldIndex.getName(), worldIndex);
	// }
	// else if(tabIndex == 4)/*隐藏印度SEN index=10*/
	// {
	// if(i == 0)
	// {
	// OnUpdateWorldIndexOther(18-1, worldIndex.getName(), worldIndex);
	// }
	// else if(i == 1)
	// {
	// OnUpdateWorldIndexOther(20-1, worldIndex.getName(), worldIndex);
	// }
	// else if(i == 2)
	// {
	// OnUpdateWorldIndexOther(15-1, worldIndex.getName(), worldIndex);
	// }
	// else if(i >= 3 && i <= 4)
	// {
	// OnUpdateWorldIndexOther(i + 13-1, worldIndex.getName(), worldIndex);
	// }
	// else if(i == 5)
	// {
	// OnUpdateWorldIndexOther(19-1, worldIndex.getName(), worldIndex);
	// }
	// }
	// }
	// catch(Exception e)
	// {
	// TDStockLog.d(TAG, "exception=WorldIndex Other foreach=" +
	// itemCodeList_worldIndex_other[i] + " > " + e.toString());
	// continue;
	// }
	// }
	// }
	//
	// // WorldFutures
	// /*
	// * tab 0: TypeName all
	// * tab 3: TypeName[0~1]
	// * tab 4: TypeName[2]
	// */
	// String itemCodeList_worldFutures_str = null;
	// String[] itemCodeList_worldFutures = null;
	// if(tabIndex == 0)
	// {
	// itemCodeList_worldFutures_str = WorldFutures.TypeName_Str_Tab0;
	// itemCodeList_worldFutures = WorldFutures.TypeName;
	// }
	// else if(tabIndex == 3)
	// {
	// itemCodeList_worldFutures_str = WorldFutures.TypeName_Str_Tab3;
	// itemCodeList_worldFutures = new String[] { WorldFutures.TypeName[0],
	// WorldFutures.TypeName[1] };
	// }
	// else if(tabIndex == 4)
	// {
	// itemCodeList_worldFutures_str = WorldFutures.TypeName_Str_Tab4;
	// itemCodeList_worldFutures = new String[] { WorldFutures.TypeName[2] };
	// }
	// if(itemCodeList_worldFutures != null)
	// {
	// Map<String, WorldFutures> worldFuturesList =
	// HttpDataBaseUtils.getDataByWorldFutures2(itemCodeList_worldFutures_str,
	// ((ITDLApplication)getApplicationContext()).getSessionAccount(),
	// ((ITDLApplication)getApplicationContext()).getSessionToken());
	// // List<WorldFutures> worldFuturesList =
	// HttpDataBaseUtils.getDataByWorldFutures(itemCodeList_worldFutures);
	// for(int i = 0; i < itemCodeList_worldFutures.length; i++)
	// {
	// try
	// {
	// WorldFutures worldFutures =
	// worldFuturesList.get(itemCodeList_worldFutures[i]);
	// if(tabIndex == 4)
	// {
	// OnUpdateWorldFutures(i + 4 + 2, worldFutures.getName(), worldFutures, 1);
	// }
	// else
	// {
	// int index = tabIndex;
	// if(tabIndex != 0)
	// index = 1;
	// OnUpdateWorldFutures(i + 4, worldFutures.getName(), worldFutures, index);
	// }
	// }
	// catch(Exception e)
	// {
	// TDStockLog.d(TAG, "exception=WorldFutures foreach=" +
	// itemCodeList_worldFutures[i] + " > " + e.toString());
	// continue;
	// }
	// }
	// }
	//
	// return super.doInBackground(params);
	// }
	//
	// @Override
	// protected void onPostExecute(Void result)
	// {
	// if(isSunflower)
	// super.onPostExecute(result);
	//
	// indexAsyncTask = null;
	// }
	// }

	// private final boolean usingBlinkColumn = true;
	private final int		blinkTime			= 300;
	private final int		INFO_CONTENT_UPDATE	= 1;
	private final Object	lockObject		= new Object();

	private Handler		UIUpdater			= new Handler()
										{
											@Override
											public void handleMessage(
													Message msg)
											{
												switch (msg.what)
												{
													case INFO_CONTENT_UPDATE:
														if (msg.arg1 < 0)
															IndexUIUpdate(
																	msg.obj,
																	false);
														else
															IndexUIUpdate(
																	msg.obj,
																	true);
														break;
												}
											}
										};

	private void IndexUIUpdate(Object iHandlerObj, boolean iBlink)
	{
		synchronized (lockObject)
		{
			if (!(iHandlerObj instanceof DoThingsReturn))
				return;

			TextView textViewObj;
			DoThingsReturn object = (DoThingsReturn) iHandlerObj;

			textViewObj = (TextView) object.data;
			if (textViewObj == null)
				return;

			textViewObj.setText(object.cmd.toString());
			if (!iBlink)
				return;

			final ViewGroup parent;

			// This is not a good way of the getting the holder. Our design
			// needs to be more rigid;
			parent = (ViewGroup) textViewObj.getParent().getParent()
					.getParent();
			if ((parent != null) && (parent.isShown()))
			{
				Animation animatAction = AnimationUtils.loadAnimation(
						BMPIndexActivity.this, R.anim.just_delay);
				animatAction.setDuration(blinkTime);
				animatAction.setAnimationListener(new AnimationListener()
				{
					@Override
					public void onAnimationEnd(Animation animation)
					{
						// parent.setBackgroundColor(_context.getResources().getColor(android.R.color.transparent));
						parent.setBackgroundResource(R.drawable.backgound_states_4_index_and_fx);
					}

					@Override
					public void onAnimationRepeat(Animation animation)
					{
					}

					@Override
					public void onAnimationStart(Animation animation)
					{
					}
				});
				parent.setBackgroundColor(BMPIndexActivity.this
						.getResources().getColor(R.color.blue));
				parent.setAnimation(animatAction);
				animatAction.startNow();
				parent.invalidate();
				// parent.startAnimation(animatAction);
			}
		}
	}

	// @Override
	// protected void SendHttpRequest()
	// {
	// if(appHost.screenIsLocked)
	// return;
	//
	// ShowHideDialog(GetDataFromHttpServer());
	// }

	@Override
	protected H_CODE GetDataFromHttpServer()
	{
		String[] itemCodes = ItemCodeTypeName(_tabIndex);

		if (itemCodes[0] != null)
			HttpAppInfo.SendBMPIndexCurrentRequest(actContext, itemCodes[0],
					this, "Index," + _tabIndex);
		if (itemCodes[1] != null)
			HttpAppInfo.SendBMPFuturesCurrentRequest(actContext,
					!((ITDLApplication) getApplicationContext())
							.getIsRealtimeFutures(), this, "Futures,"
							+ _tabIndex);
		if (itemCodes[2] != null)
			HttpAppInfo.SendBMPWorldIndexSSEICurrentRequest(actContext,
					itemCodes[2],
					!((ITDLApplication) getApplicationContext())
							.getIsRealtimeSSEI(), this,
					"WorldIndexSSEI," + _tabIndex);
		if (itemCodes[3] != null)
			HttpAppInfo.SendBMPWorldIndexCurrentRequest(actContext,
					itemCodes[3], this, "WorldIndex," + _tabIndex);
		if (itemCodes[4] != null)
			HttpAppInfo.SendBMPWorldFuturesCurrentRequest(actContext,
					itemCodes[4], this, "WorldFutures," + _tabIndex);
		return H_CODE.OK;
	}

	@Override
	protected void H_UserClient_HttpRequest_Response_Sub(
			final H_UserClient_HttpRequest_Result iResult)
	{
		final String[] params = iResult.seqID.split(",");
		final String iSeqID = params[0];
		final int tabIndex = Integer.parseInt(params[1]);

		TDStockLog.d(TAG, "SeqID=>" + params);

		if (!iResult.MStatus.equals("0"))
		{
			ShowMessageDialog(iResult.MError + "(" + iResult.MStatus + ")");
			return;
		}

		if (iResult.objMapStores.size() <= 0)
			return;

		final Runnable runnable = new Runnable()
		{
			@Override
			public void run()
			{
				updateDataByTabIndex(iResult.objMapStores, iSeqID, tabIndex);
			}
		};
		new Thread()
		{
			@Override
			public void run()
			{
				_messageHandler.post(runnable);
			}
		}.start();
	}

	private String[] ItemCodeTypeName(int tabIndex)
	{
		String[] itemArray = new String[5];
		// Index
		/*
		 * tab 0: TypeName[0~1] tab 1: TypeName all
		 */
		String itemCodeList_index = null;
		if (tabIndex == 0)
		{
			itemCodeList_index = Index.TypeName_Str_Tab0;
			// itemCodeList_index = new String[] { Index.TypeName[0],
			// Index.TypeName[1] };
		}
		else if (tabIndex == 1)
		{
			itemCodeList_index = Index.TypeName_Str_Tab1;
			// itemCodeList_index = Index.TypeName;
		}
		itemArray[0] = itemCodeList_index;

		// Futures
		/*
		 * tab 0: TypeName all tab 1: TypeName all
		 */
		if (tabIndex == 0 || tabIndex == 1)
			itemArray[1] = Futures.TypeName_Str;
		else
			itemArray[1] = null;

		// WorldIndex SSEI
		/*
		 * tab 0: TypeName[0] tab 2: TypeName all
		 */
		String itemCodeList_worldIndex_ssei = null;
		if (tabIndex == 0)
		{
			itemCodeList_worldIndex_ssei = WorldIndex.TypeName_SSEI_Str_Tab0;
			// itemCodeList_worldIndex_ssei = new String[] {
			// WorldIndex.TypeName_SSEI[0] };
		}
		else if (tabIndex == 2)
		{
			itemCodeList_worldIndex_ssei = WorldIndex.TypeName_SSEI_Str_Tab2;
			// itemCodeList_worldIndex_ssei = WorldIndex.TypeName_SSEI;
		}
		itemArray[2] = itemCodeList_worldIndex_ssei;

		// WorldIndex Other
		/*
		 * tab 0: TypeName[0~3] tab 2: TypeName[17~18] tab 3: TypeName[0],
		 * TypeName[4~13] tab 4: TypeName[1~3], TypeName[14~16]
		 */
		String itemCodeList_worldIndex_other_str = null;
		if (tabIndex == 0)
		{
			itemCodeList_worldIndex_other_str = WorldIndex.TypeName_Other_Str_Tab0;
		}
		else if (tabIndex == 2)/* 隐藏印度SEN index=10 */
		{
			itemCodeList_worldIndex_other_str = WorldIndex.TypeName_Other_Str_Tab2;
		}
		else if (tabIndex == 3)/* 隐藏印度SEN index=10 */
		{
			itemCodeList_worldIndex_other_str = WorldIndex.TypeName_Other_Str_Tab3;
		}
		else if (tabIndex == 4)/* 隐藏印度SEN index=10 */
		{
			itemCodeList_worldIndex_other_str = WorldIndex.TypeName_Other_Str_Tab4;
		}
		itemArray[3] = itemCodeList_worldIndex_other_str;

		// WorldFutures
		/*
		 * tab 0: TypeName all tab 3: TypeName[0~1] tab 4: TypeName[2]
		 */
		String itemCodeList_worldFutures_str = null;
		if (tabIndex == 0)
		{
			itemCodeList_worldFutures_str = WorldFutures.TypeName_Str_Tab0;
		}
		else if (tabIndex == 3)
		{
			itemCodeList_worldFutures_str = WorldFutures.TypeName_Str_Tab3;
		}
		else if (tabIndex == 4)
		{
			itemCodeList_worldFutures_str = WorldFutures.TypeName_Str_Tab4;
		}
		itemArray[4] = itemCodeList_worldFutures_str;

		return itemArray;
	}

	private void updateDataByTabIndex(final Map<String, ?> iObjMapStores,
			final String iSeqID, final int tabIndex)
	{
		if (iObjMapStores.size() <= 0)
			return;

		if ("Index".equals(iSeqID))
		{
			Map<String, Index> indexList = (Map<String, Index>) iObjMapStores;

			for (int i = 0; i < indexList.size(); i++)
			{
				try
				{
					Index index = indexList.get(Index.TypeName[i]);
					OnUpdateIndex(i, index.getName(), index, tabIndex);
				}
				catch (Exception e)
				{
					TDStockLog.d(TAG, "exception=Index foreach="
							+ Index.TypeName[i] + " > " + e.toString());
				}
			}
		}
		else if ("Futures".equals(iSeqID))
		{
			Map<String, Futures> futuresList = (Map<String, Futures>) iObjMapStores;

			for (int i = 0; i < Futures.TypeName.length; i++)
			{
				try
				{
					Futures futures = futuresList.get(Futures.TypeName[i]);
					OnUpdateFutures(i, futures.getName(), futures,
							tabIndex);
				}
				catch (Exception e)
				{
					TDStockLog.d(TAG, "exception=Futures foreach="
							+ Futures.TypeName[i] + " > " + e.toString());
					continue;
				}
			}
		}
		else if ("WorldIndexSSEI".equals(iSeqID))
		{
			Map<String, WorldIndex> worldIndexSSEIList = (Map<String, WorldIndex>) iObjMapStores;

			for (int i = 0; i < WorldIndex.TypeName_SSEI.length; i++)
			{
				try
				{
					WorldIndex worldIndex = worldIndexSSEIList
							.get(WorldIndex.TypeName_SSEI[i]);
					if (tabIndex == 0)
					{
						OnUpdateWorldIndexSSEI(0, worldIndex.getName(),
								worldIndex);
					}
					else
					{
						if (i == 0)
						{
							OnUpdateWorldIndexSSEI(2,
									worldIndex.getName(), worldIndex);
						}
						else if (i == 1)
						{
							OnUpdateWorldIndexSSEI(i,
									worldIndex.getName(), worldIndex);
						}
						else if (i >= 2)
						{
							OnUpdateWorldIndexSSEI(i + 1,
									worldIndex.getName(), worldIndex);
						}
					}
				}
				catch (Exception e)
				{
					TDStockLog.d(TAG,
							"exception=WorldIndex SSEI foreach="
									+ WorldIndex.TypeName_SSEI[i]
									+ " > " + e.toString());
					continue;
				}
			}
		}
		else if ("WorldIndex".equals(iSeqID))
		{
			String[] itemCodeList_worldIndex_other = null;
			if (tabIndex == 0)
			{
				itemCodeList_worldIndex_other = new String[] {
						WorldIndex.TypeName_Other[0],
						WorldIndex.TypeName_Other[1],
						WorldIndex.TypeName_Other[2],
						WorldIndex.TypeName_Other[3] };
			}
			else if (tabIndex == 2)/* 隐藏印度SEN index=10 */
			{
				itemCodeList_worldIndex_other = new String[] {
						WorldIndex.TypeName_Other[17 - 1],
						WorldIndex.TypeName_Other[18 - 1] };
			}
			else if (tabIndex == 3)/* 隐藏印度SEN index=10 */
			{
				itemCodeList_worldIndex_other = new String[] {
						WorldIndex.TypeName_Other[0],
						WorldIndex.TypeName_Other[4],
						WorldIndex.TypeName_Other[5],
						WorldIndex.TypeName_Other[6],
						WorldIndex.TypeName_Other[7],
						WorldIndex.TypeName_Other[8],
						WorldIndex.TypeName_Other[9],
						WorldIndex.TypeName_Other[10],
						WorldIndex.TypeName_Other[11],
						WorldIndex.TypeName_Other[12] /*
													 * ,
													 * WorldIndex.TypeName_Other
													 * [13]
													 */};
			}
			else if (tabIndex == 4)/* 隐藏印度SEN index=10 */
			{
				itemCodeList_worldIndex_other = new String[] {
						WorldIndex.TypeName_Other[1],
						WorldIndex.TypeName_Other[2],
						WorldIndex.TypeName_Other[3],
						WorldIndex.TypeName_Other[14 - 1],
						WorldIndex.TypeName_Other[15 - 1],
						WorldIndex.TypeName_Other[16 - 1] };
			}

			Map<String, WorldIndex> worldIndexList = (Map<String, WorldIndex>) iObjMapStores;

			for (int i = 0; i < itemCodeList_worldIndex_other.length; i++)
			{
				try
				{
					WorldIndex worldIndex = worldIndexList
							.get(itemCodeList_worldIndex_other[i]);

					if (worldIndex == null)
						continue;

					if (tabIndex == 0)
					{
						OnUpdateWorldIndexOther(i, worldIndex.getName(),
								worldIndex);
					}
					else if (tabIndex == 2)
					{
						// 深圳SZA，深圳SZB
						OnUpdateWorldIndexOther(i + 50,
								worldIndex.getName(), worldIndex);
					}
					else if (tabIndex == 3) /* 隐藏印度SEN index=10 */
					{
						TDStockLog.d(TAG, "tabIndex=" + tabIndex
								+ " , index=" + (i + 4) + " , "
								+ worldIndex.getName());
						OnUpdateWorldIndexOther(i + 4,
								worldIndex.getName(), worldIndex);
					}
					else if (tabIndex == 4)/* 隐藏印度SEN index=10 */
					{
						if (i == 0)
						{
							OnUpdateWorldIndexOther(18 - 1,
									worldIndex.getName(), worldIndex);
						}
						else if (i == 1)
						{
							OnUpdateWorldIndexOther(20 - 1,
									worldIndex.getName(), worldIndex);
						}
						else if (i == 2)
						{
							OnUpdateWorldIndexOther(15 - 1,
									worldIndex.getName(), worldIndex);
						}
						else if (i >= 3 && i <= 4)
						{
							OnUpdateWorldIndexOther(i + 13 - 1,
									worldIndex.getName(), worldIndex);
						}
						else if (i == 5)
						{
							OnUpdateWorldIndexOther(19 - 1,
									worldIndex.getName(), worldIndex);
						}
					}
				}
				catch (Exception e)
				{
					// TDStockLog.d(TAG, "exception=WorldIndex Other foreach=" +
					// itemCodeList_worldIndex_other[i] + " > " + e.toString());
					continue;
				}
			}
		}
		else if ("WorldFutures".equals(iSeqID))
		{
			String[] itemCodeList_worldFutures = null;
			if (tabIndex == 0)
			{
				itemCodeList_worldFutures = WorldFutures.TypeName;
			}
			else if (tabIndex == 3)
			{
				itemCodeList_worldFutures = new String[] {
						WorldFutures.TypeName[0],
						WorldFutures.TypeName[1] };
			}
			else if (tabIndex == 4)
			{
				itemCodeList_worldFutures = new String[] { WorldFutures.TypeName[2] };
			}

			Map<String, WorldFutures> worldFuturesList = (Map<String, WorldFutures>) iObjMapStores;

			for (int i = 0; i < itemCodeList_worldFutures.length; i++)
			{
				try
				{
					WorldFutures worldFutures = worldFuturesList
							.get(itemCodeList_worldFutures[i]);
					if (tabIndex == 4)
					{
						OnUpdateWorldFutures(i + 4 + 2,
								worldFutures.getName(), worldFutures, 1);
					}
					else
					{
						int index = tabIndex;
						if (tabIndex != 0)
							index = 1;
						OnUpdateWorldFutures(i + 4,
								worldFutures.getName(), worldFutures,
								index);
					}
				}
				catch (Exception e)
				{
					TDStockLog.d(TAG,
							"exception=WorldFutures foreach="
									+ itemCodeList_worldFutures[i]
									+ " > " + e.toString());
					continue;
				}
			}
		}
	}
}
